Skip to content

Commit

Permalink
added class names and paypal button code
Browse files Browse the repository at this point in the history
  • Loading branch information
xjamundx committed Mar 10, 2022
1 parent 8922915 commit 24a8bdc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions advanced-integration/public/app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
paypal
.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: function (data, actions) {
return fetch("/api/orders", {
method: "post",
// use the "body" param to optionally pass additional order information
// like product ids or amount
})
.then((response) => response.json())
.then((order) => order.id);
},
// Finalize the transaction after payer approval
onApprove: function (data, actions) {
return fetch(`/api/orders/${data.orderID}/capture`, {
method: "post",
})
.then((response) => response.json())
.then((orderData) => {
// Successful capture! For dev/demo purposes:
console.log(
"Capture result",
orderData,
JSON.stringify(orderData, null, 2)
);
var transaction = orderData.purchase_units[0].payments.captures[0];
alert(`Transaction ${transaction.status}: ${transaction.id}
See console for all available details
`);
// When ready to go live, remove the alert and show a success message within this page. For example:
// var element = document.getElementById('paypal-button-container');
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
},
})
.render("#paypal-button-container");

// If this returns false or the card fields aren't visible, see Step #1.
if (paypal.HostedFields.isEligible()) {
let orderId;
Expand Down
1 change: 1 addition & 0 deletions advanced-integration/views/checkout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
></script>
</head>
<body>
<div id="paypal-button-container" class="paypal-button-container"></div>
<div class="card_container">
<form id="card-form">
<label for="card-number">Card Number</label>
Expand Down

0 comments on commit 24a8bdc

Please sign in to comment.