加载中…

PayPal支付配置

调用`PayPal`支付,需要以下4个信息: + clientId + clientSecret + webhookId + currency # 开通账号 [https://www.paypal.com/](https://www.paypal.com/) 开通注册好你自己的 paypal 账号,然后进入开发者平台创建应用: [https://developer.paypal.com/developer/applications/](https://developer.paypal.com/developer/applications/) 创建好应用以后,即可查看到应用到 clientId 和 clientSecret 同时必须在账号设置中设置允许 checkout 方式收款,否则会提示没用权限的 ![](https://dcdn.it120.cc/yuque/0/2021/png/572726/1640858312379-7176c7d1-09ec-4b48-a619-fb99c8c03ab1.png) ![](https://dcdn.it120.cc/yuque/0/2021/png/572726/1640858332126-3c95468d-6217-47e4-80f2-29de43ef424e.png) ![](https://dcdn.it120.cc/yuque/0/2021/png/572726/1640858357654-4d3c7dc8-b2c2-4ee7-bd28-66d3e51f29f7.png) ![](https://dcdn.it120.cc/yuque/0/2021/png/572726/1640858380754-2f7d23c8-18f0-47d8-9e4e-f998fb538ab7.png) # 配置 webhook paypal 的支付异步通知是通过配置 webhook 来实现的,如图操作: ![](https://dcdn.it120.cc/yuque/0/2021/png/572726/1637048076546-e9d2a4a9-08da-4832-bef8-01dec07eaf90.png) 通知地址填写:https://api.it120.cc/**gooking**/pay/paypal/payBack 其中红色的 **gooking** 请换成你自己的专属域名 下面的通知事件,请勾选:PAYMENT.CAPTURE.COMPLETED 创建webhook以后,即可在列表中获取 webhookId # 货币符号 [https://developer.paypal.com/docs/api/reference/currency-codes/](https://developer.paypal.com/docs/api/reference/currency-codes/) 要保证你传的 `currency`必须是支持的货币,否则接口是无法调通的 ![](https://dcdn.it120.cc/yuque/0/2021/png/572726/1640859846812-05b51c3c-5c53-4dea-8b95-a427dbc9e53d.png) # 后台配置 将以上信息,配置到 “api工厂” 后台: 系统设置 --> 在线支付 --> 设置 paypal 支付 # 前端调用 ## 小程序支付 前端通过调用接口:`/pay/paypal/checkout` 接口发起支付即可; WXAPI SDK,可直接调用: ```javascript WXAPI.paypalCheckout({...}) ``` ## js 中发起 checkout 收款 需要先引入官方的 js ```javascript ``` 在需要出现PayPal按钮的地方,放置容器: ```html
``` 编写js文件: ```javascript paypal.Buttons({ createOrder: function(data, actions) { // This function sets up the details of the transaction, including the amount and line item details. // return actions.order.create({ // purchase_units: [{ // amount: { // value: '0.21' // } // }] // }) return _this.$wxapi.paypalCheckout({ token: getToken(), money: 1.03 }).then(res => { return res.data.orderId }) }, onApprove: function(data, actions) { // This function captures the funds from the transaction. return actions.order.capture().then(function(details) { console.log(details) // This function shows a transaction success message to your buyer. alert('Transaction completed by ' + details.payer.name.given_name) }) } }).render('#paypal-button-container') ``` # 参考资料 [https://developer.paypal.com/docs/checkout/integrate/](https://developer.paypal.com/docs/checkout/integrate/) [https://github.com/paypal/Checkout-Java-SDK](https://github.com/paypal/Checkout-Java-SDK) webhook 会回调2种类型: ~~CHECKOUT.ORDER.APPROVED 用户授权扣款~~ PAYMENT.CAPTURE.COMPLETED 订单完成 只需要勾选第二种即可