/
standalone_html_paypal_test_button.html
57 lines (49 loc) · 1.25 KB
/
standalone_html_paypal_test_button.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div id="paypal-button"></div>
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<script>
var CREATE_PAYMENT_URL = 'http://localhost:5005/api/v1/payment/paypal/create';
var EXECUTE_PAYMENT_URL = 'http://localhost:5005/api/v1/payment/paypal/execute';
paypal.Button.render({
env: 'sandbox', // 'sandbox' || 'production'
commit: true, // Show a 'Pay Now' button
payment: function() {
return paypal.request({
method: 'post',
url: CREATE_PAYMENT_URL,
headers: {
"api-token":"AQUI VA EL TOKEN DEL SERVICIO LOGIN",
},
json: {
quantity: 2 //cambiar por la cantidad de items comprados
}
}).then(function(data) {
return data.paymentID;
})
},
onAuthorize: function(data) {
return paypal.request({
method: 'post',
url: EXECUTE_PAYMENT_URL,
headers: {
"api-token":"AQUI VA EL TOKEN DEL SERVICIO LOGIN",
},
json: {
paymentID: data.paymentID,
payerID: data.payerID,
quantity: 2
}
}).then(function(res) {
console.log(res.success)
})
}
}, '#paypal-button');
</script>
</body>
</html>