How exactly integrate Server-Side REST?

webDev-cr
Contributor
Contributor

hI everybody.

 

I have this code:

 

<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>
<body>
<div id="paypal-button-container"></div>
<script>
var CREATE_PAYMENT_URL = '/paypal/create-payment';
var EXECUTE_PAYMENT_URL = '/paypal/execute-payment/';
paypal.Button.render({
env: 'sandbox', // sandbox | production
// Show the buyer a 'Pay Now' button in the checkout flow
commit: true,
// payment() is called when the button is clicked
payment: function() {
return paypal.request.post(CREATE_PAYMENT_URL).then(function(data) {

//console.log(" ID del pago retornado: " + data);
console.log(CREATE_PAYMENT_URL);
return data.id;
});
},
// onAuthorize() is called when the buyer approves the payment
onAuthorize: function(data) {
return paypal.request.post(EXECUTE_PAYMENT_URL, {
paymentID: data.paymentID,
payerID: data.payerID
}).then(function() {
// The payment is complete!
// You can now show a confirmation message to the customer
alert("Felicidades! El pago fue realizado.");
}).catch(function(err) {
console.log(err);
});
console.log(" Data " + data);
},
onCancel: function(data, actions) {
return actions.redirect();
}
}, '#paypal-button-container');
</script>
</body>

 

 I have been reading about Paypal Rest Api.

I read the function return JSON data, so what code I must to include in '/paypal/create-payment'; ?
Please, I need a complete example.

Thanks

Login to Me Too
1 REPLY 1

MTS_Jennifer
Moderator
Moderator

Here is the documentation on server side Rest API setup:

 

Server Side Rest API Integration

 

Here is the request to get the access token:

Access Token Request

 

Complete Request on your server:

Create Payment Request

 

Complete SDK for PHP Rest API Payments:

PHP SDK for Rest API Payments

 

Thank you,

Jennifer

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.