PayPal

具体API使用介绍,请参考gopay/paypal/client_test.go,gopay/paypal/order_test.go,gopay/paypal/payment_test.go


1、初始化PayPal客户端并做配置(Init PayPal Client)

import (
    "github.com/go-pay/gopay/paypal"
    "github.com/go-pay/gopay/pkg/xlog"
)

// 初始化PayPal支付客户端
client, err := paypal.NewClient(Clientid, Secret, false)
if err != nil {
    xlog.Error(err)
    return
}
// 打开Debug开关,输出日志,默认关闭
client.DebugSwitch = gopay.DebugOn

2、API 方法调用及入参(Call API)

Orders:Orders API

Payments:Payments API

  • Create Orders example
import (
    "github.com/go-pay/gopay"
    "github.com/go-pay/gopay/paypal"
    "github.com/go-pay/gopay/pkg/util"
    "github.com/go-pay/gopay/pkg/xlog"
)
// Create Orders example
var pus []*paypal.PurchaseUnit
var item = &paypal.PurchaseUnit{
    ReferenceId: util.GetRandomString(16),
    Amount: &paypal.Amount{
        CurrencyCode: "USD",
        Value:        "8",
    },
}
pus = append(pus, item)

bm := make(gopay.BodyMap)
bm.Set("intent", "CAPTURE").
    Set("purchase_units", pus)

ppRsp, err := client.CreateOrder(ctx, bm)
if err != nil {
    xlog.Error(err)
    return
}
if ppRsp.Code != paypal.Success {
    // do something
    return
}

附录:

PayPal API

  • AccessToken
    • 获取AccessToken(Get AccessToken):client.GetAccessToken()
  • 订单
    • 创建订单(Create order):client.CreateOrder()
    • 订单详情(Show order details):client.OrderDetail()
    • 更新订单(Update order):client.UpdateOrder()
    • 订单支付授权(Authorize payment for order):client.OrderAuthorize()
    • 订单支付捕获(Capture payment for order):client.OrderCapture()
  • 支付
    • 支付授权详情(Show details for authorized payment):client.PaymentAuthorizeDetail()
    • 重新授权支付授权(Reauthorize authorized payment):client.PaymentReauthorize()
    • 作废支付授权(Void authorized payment):client.PaymentAuthorizeVoid()
    • 支付授权捕获(Capture authorized payment):client.PaymentAuthorizeCapture()
    • 支付捕获详情(Show captured payment details):client.PaymentCaptureDetail()
    • 支付捕获退款(Refund captured payment):client.PaymentCaptureRefund()
    • 支付退款详情(Show refund details):client.PaymentRefundDetail()
最后编辑: kuteng  文档更新时间: 2021-10-29 09:42   作者:kuteng