What are basic create-paypal-order and capture-paypal-order files?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I used to use the button creation wizard which generated the javascript/html for me. But that has now stopped, we need backends. My server does not support node.js, but does support php.
I have this on my html page:
<!-- Replace "test" with your own sandbox Business account app client ID -->
<script src="https://www.paypal.com/sdk/js?client-id=test¤cy=USD"></script>
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
// Order is created on the server and the order id is returned
createOrder() {
return fetch("/my-server/create-paypal-order", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
// use the "body" param to optionally pass additional order information
// like product skus and quantities
body: JSON.stringify({
cart: [
{
sku: "YOUR_PRODUCT_STOCK_KEEPING_UNIT",
quantity: "YOUR_PRODUCT_QUANTITY",
},
],
}),
})
.then((response) => response.json())
.then((order) => order.id);
},
// Finalize the transaction on the server after payer approval
onApprove(data) {
return fetch("/my-server/capture-paypal-order", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
orderID: data.orderID
})
})
.then((response) => response.json())
.then((orderData) => {
// Successful capture! For dev/demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
const transaction = orderData.purchase_units[0].payments.captures[0];
alert(`Transaction ${transaction.status}: ${transaction.id}\n\nSee console for all available details`);
// When ready to go live, remove the alert and show a success message within this page. For example:
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: window.location.href = 'thank_you.html';
});
}
}).render('#paypal-button-container');
</script>
So it appears I need to write some php files create-paypal-order.php and capture-paypal-order.php
Does anyone know what I need to write in those files?
All I want to do is charge someone UK£10 for a product with a name "Product" and make sure Paypal send me an email telling me that charge has ocurred. (I do NOT want to add anything to a database.)
I then want them to redirect to a page with a KeyCode (that page is already written and has been working for years with the old button system).
So what does create-paypal-order.php look like?
What does capture-paypal-order.php look like?
Haven't Found your Answer?
It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.
- Help Needed: SOFTEX Filing for SaaS Sales via PayPal in India in PayPal Upgrade Community
- Javascript SDK throws 400 when trying to create order using Debit or Credit card in PayPal Payments Standard
- HTTP GET /api/orders results in Status 403 Forbidden in Sandbox Environment
- IPN requests not reaching the listener in REST APIs
- Completing an Advanced Integration in PayPal Payments Standard