Skip to content

Commit 1ded025

Browse files
authored
Update payment.js
1 parent 6feab60 commit 1ded025

File tree

1 file changed

+96
-95
lines changed

1 file changed

+96
-95
lines changed

payment_integration/payment.js

Lines changed: 96 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,97 @@
11
function initPayPalButton() {
2-
var description = document.querySelector('#smart-button-container #description');
3-
var amount = document.querySelector('#smart-button-container #amount');
4-
var descriptionError = document.querySelector('#smart-button-container #descriptionError');
5-
var priceError = document.querySelector('#smart-button-container #priceLabelError');
6-
var invoiceid = document.querySelector('#smart-button-container #invoiceid');
7-
var invoiceidError = document.querySelector('#smart-button-container #invoiceidError');
8-
var invoiceidDiv = document.querySelector('#smart-button-container #invoiceidDiv');
9-
10-
var elArr = [description, amount];
11-
12-
if (invoiceidDiv.firstChild.innerHTML.length > 1) {
13-
invoiceidDiv.style.display = "block";
14-
}
15-
16-
var purchase_units = [];
17-
purchase_units[0] = {};
18-
purchase_units[0].amount = {};
19-
20-
function validate(event) {
21-
return event.value.length > 0;
22-
}
23-
24-
paypal.Buttons({
25-
style: {
26-
color: 'gold',
27-
shape: 'pill',
28-
label: 'pay',
29-
layout: 'horizontal',
30-
31-
},
32-
33-
onInit: function (data, actions) {
34-
actions.disable();
35-
36-
if(invoiceidDiv.style.display === "block") {
37-
elArr.push(invoiceid);
38-
}
39-
40-
elArr.forEach(function (item) {
41-
item.addEventListener('keyup', function (event) {
42-
var result = elArr.every(validate);
43-
if (result) {
44-
actions.enable();
45-
} else {
46-
actions.disable();
47-
}
48-
});
49-
});
50-
},
51-
52-
onClick: function () {
53-
if (description.value.length < 1) {
54-
descriptionError.style.visibility = "visible";
55-
} else {
56-
descriptionError.style.visibility = "hidden";
57-
}
58-
59-
if (amount.value.length < 1) {
60-
priceError.style.visibility = "visible";
61-
} else {
62-
priceError.style.visibility = "hidden";
63-
}
64-
65-
if (invoiceid.value.length < 1 && invoiceidDiv.style.display === "block") {
66-
invoiceidError.style.visibility = "visible";
67-
} else {
68-
invoiceidError.style.visibility = "hidden";
69-
}
70-
71-
purchase_units[0].description = description.value;
72-
purchase_units[0].amount.value = amount.value;
73-
74-
if(invoiceid.value !== '') {
75-
purchase_units[0].invoice_id = invoiceid.value;
76-
}
77-
},
78-
79-
createOrder: function (data, actions) {
80-
return actions.order.create({
81-
purchase_units: purchase_units,
82-
});
83-
},
84-
85-
onApprove: function (data, actions) {
86-
return actions.order.capture().then(function (details) {
87-
alert('Transaction completed by ' + details.payer.name.given_name + '!');
88-
});
89-
},
90-
91-
onError: function (err) {
92-
console.log(err);
93-
}
94-
}).render('#paypal-button-container');
95-
}
96-
initPayPalButton();
2+
var description = document.querySelector('#smart-button-container #description');
3+
var amount = document.querySelector('#smart-button-container #amount');
4+
var descriptionError = document.querySelector('#smart-button-container #descriptionError');
5+
var priceError = document.querySelector('#smart-button-container #priceLabelError');
6+
var invoiceid = document.querySelector('#smart-button-container #invoiceid');
7+
var invoiceidError = document.querySelector('#smart-button-container #invoiceidError');
8+
var invoiceidDiv = document.querySelector('#smart-button-container #invoiceidDiv');
9+
10+
var elArr = [description, amount];
11+
12+
if (invoiceidDiv.firstChild.innerHTML.length > 1) {
13+
invoiceidDiv.style.display = "block";
14+
}
15+
16+
var purchase_units = [];
17+
purchase_units[0] = {};
18+
purchase_units[0].amount = {};
19+
20+
function validate(event) {
21+
return event.value.length > 0;
22+
}
23+
24+
paypal.Buttons({
25+
style: {
26+
color: 'gold',
27+
shape: 'pill',
28+
label: 'pay',
29+
layout: 'horizontal',
30+
31+
},
32+
33+
onInit: function(data, actions) {
34+
actions.disable();
35+
36+
if (invoiceidDiv.style.display === "block") {
37+
elArr.push(invoiceid);
38+
}
39+
40+
elArr.forEach(function(item) {
41+
item.addEventListener('keyup', function(event) {
42+
var result = elArr.every(validate);
43+
if (result) {
44+
actions.enable();
45+
} else {
46+
actions.disable();
47+
}
48+
});
49+
});
50+
},
51+
52+
onClick: function() {
53+
if (description.value.length < 1) {
54+
descriptionError.style.visibility = "visible";
55+
} else {
56+
descriptionError.style.visibility = "hidden";
57+
}
58+
59+
if (amount.value.length < 1) {
60+
priceError.style.visibility = "visible";
61+
} else {
62+
priceError.style.visibility = "hidden";
63+
}
64+
65+
if (invoiceid.value.length < 1 && invoiceidDiv.style.display === "block") {
66+
invoiceidError.style.visibility = "visible";
67+
} else {
68+
invoiceidError.style.visibility = "hidden";
69+
}
70+
71+
purchase_units[0].description = description.value;
72+
purchase_units[0].amount.value = amount.value;
73+
74+
if (invoiceid.value !== '') {
75+
purchase_units[0].invoice_id = invoiceid.value;
76+
}
77+
},
78+
79+
createOrder: function(data, actions) {
80+
return actions.order.create({
81+
purchase_units: purchase_units,
82+
});
83+
},
84+
85+
onApprove: function(data, actions) {
86+
return actions.order.capture().then(function(details) {
87+
alert('Transaction completed by ' + details.payer.name.given_name + '!');
88+
});
89+
},
90+
91+
onError: function(err) {
92+
console.log(err);
93+
}
94+
}).render('#paypal-button-container');
95+
}
96+
initPayPalButton();
97+

0 commit comments

Comments
 (0)