Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit accd40b

Browse files
committed
Update paypal processing
1 parent 7e78591 commit accd40b

File tree

1 file changed

+66
-78
lines changed

1 file changed

+66
-78
lines changed

views/default/donate.html

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{{user_navs = True}}
22
{{extend 'layout.html'}}
33

4-
{{ if settings.academy_mode: }}
5-
<script src="https://www.paypalobjects.com/api/checkout.js" type="text/javascript"></script>
6-
{{ pass }}
74
{{block statusbar}}
85
{{end}}
96

@@ -39,86 +36,77 @@ <h1>Support Runestone Interactive</h1>
3936
</div>
4037
</div>
4138
</div>
42-
<div id="paypal-button"></div>
39+
<div id="paypal-button-container" class="col-md-8 col-md-offset-2"></div>
4340

44-
<div class="panel panel-default" style="text-align: center; font-size: large; width: 80%; margin-left: auto; margin-right: auto;">
45-
<div class="panel-heading" >
46-
<h2>Support with Venmo</h2>
47-
</div>
48-
<div class="panel panel-body">
49-
<p style="padding: 5px;">For your Convenience you can also <strong>Venmo</strong> your support to @RunestoneInteractive
50-
<button type="button" class="btn btn-info btn-sm" onclick="venmosupport()">I have Venmo'd my Support</button>
51-
</p>
52-
</div>
53-
</div>
5441

55-
<script>
56-
paypal.Button.render({
57-
env: 'production', // Or 'sandbox', 'production'
58-
client: {
59-
sandbox: 'AVsIrTPVGQOcMILmCSyfLioKBiqdTgAzC_ax74na1CZ0HZV0EPf9Vq7PDp_sWPeqNitq0yRGRYq5vjDp',
60-
production: 'ASkp77N-Kiw5GKOF_0I13P0GCW6lrnaukdVqeFykz7zBT9F-WXHRIisBsau5VEmC-vCKCzt--41kaOjb'
61-
},
62-
63-
commit: true, // Show a 'Pay Now' button
64-
65-
style: {
66-
color: 'blue',
67-
size: 'responsive',
68-
layout: 'vertical'
69-
},
70-
71-
payment: function(data, actions) {
72-
var amt_opts = document.getElementsByName("donate")
73-
var amt = ""
74-
for (let rb of amt_opts) {
75-
if (rb.type === "radio" & rb.checked) {
76-
amt = rb.value
42+
43+
<script src="https://www.paypal.com/sdk/js?client-id=AVsIrTPVGQOcMILmCSyfLioKBiqdTgAzC_ax74na1CZ0HZV0EPf9Vq7PDp_sWPeqNitq0yRGRYq5vjDp
44+
&currency=USD&intent=capture&enable-funding=venmo" data-sdk-integration-source="integrationbuilder"></script>
45+
46+
<script>
47+
const fundingSources = [
48+
paypal.FUNDING.PAYPAL,
49+
paypal.FUNDING.VENMO,
50+
paypal.FUNDING.CARD
51+
]
52+
53+
for (const fundingSource of fundingSources) {
54+
const paypalButtonsComponent = paypal.Buttons({
55+
fundingSource: fundingSource,
56+
57+
// optional styling for buttons
58+
// https://developer.paypal.com/docs/checkout/standard/customize/buttons-style-guide/
59+
style: {
60+
shape: 'rect',
61+
height: 40,
62+
},
63+
64+
// set up the transaction
65+
createOrder: (data, actions) => {
66+
// pass in any options from the v2 orders create call:
67+
// https://developer.paypal.com/api/orders/v2/#orders-create-request-body
68+
const createOrderPayload = {
69+
purchase_units: [
70+
{
71+
amount: {
72+
value: '88.44',
73+
},
74+
},
75+
],
7776
}
77+
78+
return actions.order.create(createOrderPayload)
79+
},
80+
81+
// finalize the transaction
82+
onApprove: (data, actions) => {
83+
const captureOrderHandler = (details) => {
84+
const payerName = details.payer.name.given_name
85+
console.log('Transaction completed!')
86+
}
87+
88+
return actions.order.capture().then(captureOrderHandler)
89+
},
90+
91+
// handle unrecoverable errors
92+
onError: (err) => {
93+
console.error(
94+
'An error prevented the buyer from checking out with PayPal',
95+
)
96+
},
97+
})
98+
99+
if (paypalButtonsComponent.isEligible()) {
100+
paypalButtonsComponent
101+
.render('#paypal-button-container')
102+
.catch((err) => {
103+
console.error('PayPal Buttons failed to render')
104+
})
105+
} else {
106+
console.log('The funding source is ineligible')
78107
}
79-
if (amt === "") {
80-
amt = document.getElementById("donateother").value
81-
}
82-
return actions.payment.create({
83-
payment: {
84-
transactions: [
85-
{
86-
amount: { total: amt, currency: 'USD' }
87-
}
88-
]
89-
}
90-
});
91-
},
92-
93-
onAuthorize: function(data, actions) {
94-
return actions.payment.execute().then(function(payment) {
95-
96-
// The payment is complete!
97-
// You can now show a confirmation message to the customer
98-
$.get("/{{=request.application}}/ajax/save_donate")
99-
alert('Payment successful - Thank you! ')
100-
window.location.href = "/{{=request.application}}/default"
101-
});
102-
},
103-
104-
onCancel: function(data, actions) {
105-
/*
106-
* Buyer cancelled the payment
107-
*/
108-
},
109-
110-
onError: function(err) {
111-
/*
112-
* An error occurred during the transaction
113-
*/
114108
}
115-
}, '#paypal-button');
116-
117-
function venmosupport() {
118-
$.get("/{{=request.application}}/ajax/save_donate");
119-
window.location.href = "/{{=request.application}}/default";
120-
}
121-
</script>
109+
</script>
122110

123111
{{ if request.args: }}
124112
<script>

0 commit comments

Comments
 (0)