Loading…

PayPal payment configuration

To call `PayPal` to pay, the following 4 pieces of information are required: +clientId + clientSecret + webhookId + currency# Open an account [https://www.paypal.com/](https://www.paypal.com/) Open and register your own PayPal account, and then enter the developer platform to create an application: [https://developer.paypal.com/developer/applications/](https://developer.paypal.com/developer/applications/) After creating the application, you can view the application toclientId and clientSecretAt the same time, you must set up the account settings to allow the checkout method to collect money, otherwise it will prompt that the permission is not used. ![](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) # Configure webhook PayPal's payment asynchronous notification is implemented by configuring webhook, as shown in the figure: ![](https://dcdn.it120.cc/yuque/0/2021/png/572726/1637048076546-e9d2a4a9-08da-4832-bef8-01dec07eaf90.png) Fill in the notification address: https://common.apifm.com/**gooking**/pay/paypal/payBack Among them red **gooking** Please change it to your own exclusive domain name Please check the following notification events: PAYMENT.CAPTURE.COMPLETED After creating a webhook, you can get the webhookId in the list # Currency symbol [https://developer.paypal.com/docs/api/reference/currency-codes/](https://developer.paypal.com/docs/api/reference/currency-codes/) Make sure that the `currency` you pass must be a supported currency, otherwise the interface cannot be adjusted. ![](https://dcdn.it120.cc/yuque/0/2021/png/572726/1640859846812-05b51c3c-5c53-4dea-8b95-a427dbc9e53d.png) #Backend configuration Configure the above information to the "apifm" background: System settings --> Online payment --> Set up paypal payment # Front-end call ## Mini program payment The front end can initiate payment by calling the interface: `/pay/paypal/checkout` interface; WXAPI SDK can be called directly: ```javascript WXAPI.paypalCheckout({...}) ``` ## Initiate checkout collection in js You need to introduce the official js first ```javascript``` Where the PayPal button needs to appear, place the container: ```html
``` Write js file: ```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') ``` # References [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 will call back 2 types: ~~CHECKOUT.ORDER.APPROVED User authorized deduction~~ PAYMENT.CAPTURE.COMPLETED order completed Just check the second option