具体API使用介绍,请参考
gopay/paypal/client_test.go
,gopay/paypal/order_test.go
,gopay/paypal/payment_test.go
等xxx_test.go
已实现API列表附录:API List
PayPal官方文档:Official Document
import (
"github.com/go-pay/gopay/paypal"
"github.com/go-pay/xlog"
)
// 初始化PayPal支付客户端
client, err := paypal.NewClient(Clientid, Secret, false)
if err != nil {
xlog.Error(err)
return
}
// 自定义配置http请求接收返回结果body大小,默认 10MB
client.SetBodySize() // 没有特殊需求,可忽略此配置
// 打开Debug开关,输出日志,默认关闭
client.DebugSwitch = gopay.DebugOn
Orders:Orders API
Payments:Payments API
Subscriptions:Subscriptions API
import (
"github.com/go-pay/gopay"
"github.com/go-pay/gopay/paypal"
"github.com/go-pay/util"
"github.com/go-pay/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).
SetBodyMap("payment_source", func(b gopay.BodyMap) {
b.SetBodyMap("paypal", func(bb gopay.BodyMap) {
bb.SetBodyMap("experience_context", func(bbb gopay.BodyMap) {
bbb.Set("brand_name", "gopay").
Set("locale", "en-US").
Set("shipping_preference", "NO_SHIPPING").
Set("user_action", "PAY_NOW").
Set("return_url", "http://xxx/return").
Set("cancel_url", "http://xxx/cancel")
})
})
})
ppRsp, err := client.CreateOrder(ctx, bm)
if err != nil {
xlog.Error(err)
return
}
if ppRsp.Code != 200 {
// do something
return
}
import (
"github.com/go-pay/gopay"
"github.com/go-pay/xlog"
)
// Capture payment for order
//bm := make(gopay.BodyMap)
//bm.SetBodyMap("payment_source", func(b gopay.BodyMap) {
// b.SetBodyMap("token", func(b gopay.BodyMap) {
// b.Set("id", "The PayPal-generated ID for the token").
// Set("type", "BILLING_AGREEMENT")
// })
//})
ppRsp, err := client.OrderCapture(ctx, "4X223967G91314611", nil)
if err != nil {
xlog.Error(err)
return
}
if ppRsp.Code != paypal.Success {
// do something
return
}
client.GetAccessToken()
client.InvoiceNumberGenerate()
client.InvoiceList()
client.InvoiceCreate()
client.InvoiceDelete()
client.InvoiceUpdate()
client.InvoiceDetail()
client.InvoiceGenerateQRCode()
client.InvoicePaymentRecord()
client.InvoicePaymentDelete()
client.InvoiceRefundRecord()
client.InvoiceRefundDelete()
client.InvoiceSendRemind()
client.InvoiceSend()
client.InvoiceSearch()
client.InvoiceTemplateList()
client.InvoiceTemplateCreate()
client.InvoiceTemplateDelete()
client.InvoiceTemplateUpdate()
client.CreateOrder()
client.OrderDetail()
client.UpdateOrder()
client.OrderAuthorize()
client.OrderCapture()
client.OrderConfirm()
client.PaymentAuthorizeDetail()
client.PaymentReauthorize()
client.PaymentAuthorizeVoid()
client.PaymentAuthorizeCapture()
client.PaymentCaptureDetail()
client.PaymentCaptureRefund()
client.PaymentRefundDetail()
client.CreateBatchPayout()
client.ShowPayoutBatchDetails()
client.ShowPayoutItemDetails()
client.CancelUnclaimedPayoutItem()
client.CreateBillingPlan()