-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
129 lines (111 loc) · 3.85 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>PayPal Demo</title>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
</head>
<body>
<div id="paypal-button"></div>
<script>
var CURRENCY = 'USD';
var SUBTOTAL = '1.80';
var TAX = '0.10';
var SHIPPING = '1.00';
var SHIPPING_DISCOUNT = '-1.00';
var TOTAL = '1.90';
paypal.Button.render({
env: 'sandbox', // Or 'sandbox',
commit: true, // Show a 'Pay Now' button
client: {
sandbox: 'AdR9nioMB7a6Nh-INzhtTSgABsXSMVtL_hizMEwMVxT0e5vKJI4ckBaWDls2d1n-5zCVgyjoqaVjHCxR'
},
style: {
label: 'paypal',
size: 'small',
shape: 'rect',
color: 'gold'
},
// Set up the payment here
payment: function (data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
amount: {
total: TOTAL,
currency: CURRENCY,
details: {
subtotal: SUBTOTAL,
tax: TAX,
shipping: SHIPPING,
shipping_discount: SHIPPING_DISCOUNT
}
},
description: 'The payment transaction description',
//invoice_number: '48787589673',
item_list: {
items: [
{name: 'Gold Membership', quantity: '1', price: '0.45', currency: CURRENCY},
{name: 'Silver Membership', quantity: '1', price: '0.45', currency: CURRENCY},
{name: 'Bronce Membership', quantity: '1', price: '0.45', currency: CURRENCY},
{name: 'Titanio Membership', quantity: '1', price: '0.45', currency: CURRENCY},
]
}
}
],
note_to_payer: 'Contact us for any questions on your order'
}
});
},
// Execute the payment here
onAuthorize: function (data, actions) {
// Get the payment details
// return actions.payment.get().then(function(data) {
/*var shipping = data.payer.payer_info.shipping_address;
console.log(data.payment.payer.payer_info);
console.log(
shipping.recipient_name + '\n' +
shipping.line1 + '\n' +
shipping.city + '\n' +
shipping.state + '\n' +
shipping.postal_code + '\n' +
shipping.country_code
);
$.each(data, function(index, value) {
console.log(index+ ": "+ value);
});*/
return actions.payment.execute().then(function (payment) {
// The payment is complete!
// You can now show a confirmation message to the customer
window.alert('Payment Complete!');
// Get payer info
var payer = payment.payer.payer_info;
console.log("Email: " + payer.email);
console.log("Name: " + payer.first_name + ' ' + payer.last_name);
// Get payment info
console.log("Id: " + payment.id);
console.log("Intent: " + payment.intent);
console.log("State: " + payment.state);
});
//});
},
onCancel: function (data, actions) {
/*
* Buyer cancelled the payment
*/
console.log('Payment was cancelled!');
},
onError: function (err) {
/*
* An error occurred during the transaction
*/
console.log(err);
window.alert('There was an error');
}
}, '#paypal-button');
</script>
</body>
</html>