帮酷LOGO
  • 显示原文与译文双语对照的内容
Golang client for PayPal REST API

  • 源代码名称:PayPal-Go-SDK
  • 源代码网址:http://www.github.com/logpacker/PayPal-Go-SDK
  • PayPal-Go-SDK源代码文档
  • PayPal-Go-SDK源代码下载
  • Git URL:
    git://www.github.com/logpacker/PayPal-Go-SDK.git
  • Git Clone代码到本地:
    git clone http://www.github.com/logpacker/PayPal-Go-SDK
  • Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/logpacker/PayPal-Go-SDK
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
  • Go Report CardBuild StatusGodocChat at https://gitter.im/logpacker/PayPal-Go-SDKSourcegraph

    转到 PayPal REST API 客户端

    覆盖

    • 发布/v1/oauth2/token
    • 发布/v1/payments/payment
    • 获取/v1/payments/payment/ID
    • 获取/v1/payments/payment
    • 获取/v1/payments/authorization/ID
    • POST/v1/payments/authorization//捕获
    • POST/v1/payments/authorization//void
    • POST/v1/payments/authorization//重新授权
    • 获取/v1/payments/sale/ID
    • POST/v1/payments/sale/ID/退款
    • 获取/v1/payments/refund/ID
    • 获取/v1/payments/orders/ID
    • POST/v1/payments/orders//授权
    • POST/v1/payments/orders//捕获
    • POST/v1/payments/orders//do
    • 发布/v1/identity/openidconnect/tokenservice
    • 获取/v1/identity/openidconnect/userinfo/?schema= 架构
    • 发布/v1/payments/payouts
    • 获取/v1/payments/payouts/ID
    • 获取/v1/payments/payouts-item/ID
    • POST/v1/payments/payouts-item//取消
    • 获取/v1/payment-experience/web-profiles
    • 发布/v1/payment-experience/web-profiles
    • 获取/v1/payment-experience/web-profiles/ID
    • 放置/v1/payment-experience/web-profiles/
    • 删除/v1/payment-experience/web-profiles/
    • 发布/v1/vault/credit-cards
    • 删除/v1/vault/credit-cards/
    • 补丁/v1/vault/credit-cards/
    • 获取/v1/vault/credit-cards/ID
    • 获取/v1/vault/credit-cards
    • 发布/v1/payments/billing-plans
    • 补丁/v1/payments/billing-plans/
    • 发布/v1/payments/billing-agreements
    • POST/v1/payments/billing-agreements//协议执行

    缺少终结点

    这里SDK客户端中可能缺少某些端点,但你可以使用内置的 paypalsdk函数来执行请求:NewClient -> NewRequest -> SendWithAuth

    新客户

    import"github.com/logpacker/PayPal-Go-SDK"// Create a client instancec, err:= paypalsdk.NewClient("clientID", "secretID", paypalsdk.APIBaseSandBox)
    c.SetLog(os.Stdout) // Set log to terminal stdoutaccessToken, err:= c.GetAccessToken()

    创建直接paypal付款

    amount:= paypalsdk.Amount{
     Total: "7.00",
     Currency: "USD",
    }redirectURI:="http://example.com/redirect-uri"cancelURI:="http://example.com/cancel-uri"description:="Description for this payment"paymentResult, err:= c.CreateDirectPaypalPayment(amount, redirectURI, cancelURI, description)

    创建自定义付款

    p:= paypalsdk.Payment{
     Intent: "sale",
     Payer: &paypalsdk.Payer{
     PaymentMethod: "credit_card",
     FundingInstruments: []paypalsdk.FundingInstrument{paypalsdk.FundingInstrument{
     CreditCard: &paypalsdk.CreditCard{
     Number: "4111111111111111",
     Type: "visa",
     ExpireMonth: "11",
     ExpireYear: "2020",
     CVV2: "777",
     FirstName: "John",
     LastName: "Doe",
     },
     }},
     },
     Transactions: []paypalsdk.Transaction{paypalsdk.Transaction{
     Amount: &paypalsdk.Amount{
     Currency: "USD",
     Total: "7.00",
     },
     Description: "My Payment",
     }},
     RedirectURLs: &paypalsdk.RedirectURLs{
     ReturnURL: "http://...",
     CancelURL: "http://...",
     },
    }paymentResponse, err:= client.CreatePayment(p)

    执行已经批准的付款

    paymentID:="PAY-17S8410768582940NKEE66EQ"payerID:="7E7MGXCWTTKK2"executeResult, err:= c.ExecuteApprovedPayment(paymentID, payerID)

    通过身份证获得付款

    payment, err:= c.GetPayment("PAY-17S8410768582940NKEE66EQ")

    获取付款列表

    payments, err:= c.GetPayments()

    通过ID获得授权

    auth, err:= c.GetAuthorization("2DC87612EK520411B")

    捕获授权

    capture, err:= c.CaptureAuthorization(authID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"}, true)

    无效授权

    auth, err:= c.VoidAuthorization(authID)

    授权授权

    auth, err:= c.ReauthorizeAuthorization(authID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"})

    ID销售

    sale, err:= c.GetSale("36C38912MN9658832")

    按ID进行退款销售

    // Fullrefund, err:= c.RefundSale(saleID, nil)// Partialrefund, err:= c.RefundSale(saleID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"})

    通过身份证获得退款

    refund, err:= c.GetRefund("O-4J082351X3132253H")

    获取 ORDER BY ID

    order, err:= c.GetOrder("O-4J082351X3132253H")

    授权订单

    auth, err:= c.AuthorizeOrder(orderID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"})

    捕获顺序

    capture, err:= c.CaptureOrder(orderID, &paypalsdk.Amount{Total: "7.00", Currency: "USD"}, true, nil)

    的无效顺序

    order, err:= c.VoidOrder(orderID)

    身份

    token, err:= c.GrantNewAccessTokenFromAuthCode("<Authorization-Code>", "http://example.com/myapp/return.php")//.. . or by refresh tokentoken, err:= c.GrantNewAccessTokenFromRefreshToken("<Refresh-Token>")

    检索用户信息

    userInfo, err:= c.GetUserInfo("openid")

    为电子邮件创建单一付款

    payout:= paypalsdk.Payout{
     SenderBatchHeader: &paypalsdk.SenderBatchHeader{
     EmailSubject: "Subject will be displayed on PayPal",
     },
     Items: []paypalsdk.PayoutItem{
     paypalsdk.PayoutItem{
     RecipientType: "EMAIL",
     Receiver: "single-email-payout@mail.com",
     Amount: &paypalsdk.AmountPayout{
     Value: "15.11",
     Currency: "USD",
     },
     Note: "Optional note",
     SenderItemID: "Optional Item ID",
     },
     },
    }payoutResp, err:= c.CreateSinglePayout(payout)

    通过标识获得付款

    payout, err:= c.GetPayout("PayoutBatchID")

    按ID获取付款项目

    payoutItem, err:= c.GetPayoutItem("PayoutItemID")

    按ID取消未被认领的付款项

    payoutItem, err:= c.CancelPayoutItem("PayoutItemID")

    创建网络体验配置文件

    webprofile:=WebProfile{
     Name: "YeowZa! T-Shirt Shop",
     Presentation: Presentation{
     BrandName: "YeowZa! Paypal",
     LogoImage: "http://www.yeowza.com",
     LocaleCode: "US",
     },
     InputFields: InputFields{
     AllowNote: true,
     NoShipping: NoShippingDisplay,
     AddressOverride: AddrOverrideFromCall,
     },
     FlowConfig: FlowConfig{
     LandingPageType: LandingPageTypeBilling,
     BankTXNPendingURL: "http://www.yeowza.com",
     },
    }result, err:= c.CreateWebProfile(webprofile)

    获得网络体验配置文件

    webprofile, err:= c.GetWebProfile("XP-CP6S-W9DY-96H8-MVN2")

    列表网页体验配置文件

    webprofiles, err:= c.GetWebProfiles()

    更新网站体验配置文件

    webprofile:=WebProfile{
     ID: "XP-CP6S-W9DY-96H8-MVN2",
     Name: "Shop YeowZa! YeowZa! ",
    }err:= c.SetWebProfile(webprofile)

    删除网站体验配置文件

    err:= c.DeleteWebProfile("XP-CP6S-W9DY-96H8-MVN2")

    // Store CCc.StoreCreditCard(paypalsdk.CreditCard{
     Number: "4417119669820331",
     Type: "visa",
     ExpireMonth: "11",
     ExpireYear: "2020",
     CVV2: "874",
     FirstName: "Foo",
     LastName: "Bar",
    })// Delete itc.DeleteCreditCard("CARD-ID-123")// Edit itc.PatchCreditCard("CARD-ID-123", []paypalsdk.CreditCardField{
     paypalsdk.CreditCardField{
     Operation: "replace",
     Path: "/billing_address/line1",
     Value: "New value",
     },
    })// Get itc.GetCreditCard("CARD-ID-123")// Get all stored credit cardsc.GetCreditCards(nil)

    :如何贡献

    • fork 存储库
    • 添加/修复某些内容
    • 检查测试是否正在传递
    • 创建 PR

    测试

    • 单元测试:go test
    • 集成测试:go test -tags=integration



    Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语