Skip to content

Commit de0f59f

Browse files
mrsaicharan1kushthedude
authored andcommitted
feat: integrated payment component for event invoice (#3351)
* integrared payment component for event invoice * paypal-invoice dit success result * linting issues fix
1 parent bcc27e7 commit de0f59f

File tree

3 files changed

+114
-51
lines changed

3 files changed

+114
-51
lines changed

app/components/paypal-button.js

Lines changed: 110 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,123 @@ export default Component.extend({
88

99
async didInsertElement() {
1010
this._super(...arguments);
11-
let order = this.data;
12-
let createPayload = {
13-
'data': {
14-
'attributes': {
15-
'return-url' : `${window.location.origin}/orders/${order.identifier}/view`,
16-
'cancel-url' : `${window.location.origin}/orders/${order.identifier}/pending`
11+
if (this.paymentFor === 'order') {
12+
let order = this.data;
13+
let createPayload = {
14+
'data': {
15+
'attributes': {
16+
'return-url' : `${window.location.origin}/orders/${order.identifier}/view`,
17+
'cancel-url' : `${window.location.origin}/orders/${order.identifier}/pending`
18+
},
19+
'type': 'paypal-payment'
20+
}
21+
};
22+
23+
paypal.Button.render({
24+
commit: true,
25+
26+
style: {
27+
label : 'pay',
28+
size : 'medium', // tiny, small, medium
29+
color : 'gold', // orange, blue, silver
30+
shape : 'pill' // pill, rect
1731
},
18-
'type': 'paypal-payment'
19-
}
20-
};
2132

22-
paypal.Button.render({
23-
commit: true,
33+
payment: () => {
34+
return this.loader.post(`orders/${order.identifier}/create-paypal-payment`, createPayload)
35+
.then(res => {
36+
return res.payment_id;
37+
});
38+
},
39+
40+
onAuthorize: data => {
41+
// this callback will be for authorizing the payments
42+
let chargePayload = {
43+
'data': {
44+
'attributes': {
45+
'stripe' : null,
46+
'paypal_payer_id' : data.payerID,
47+
'paypal_payment_id' : data.paymentID
48+
},
49+
'type': 'charge'
50+
}
51+
};
52+
let config = {
53+
skipDataTransform: true
54+
};
55+
chargePayload = JSON.stringify(chargePayload);
56+
return this.loader.post(`orders/${order.identifier}/charge`, chargePayload, config)
57+
.then(charge => {
58+
if (charge.data.attributes.status) {
59+
this.notify.success(charge.data.attributes.message);
60+
this.router.transitionTo('orders.view', order.identifier);
61+
} else {
62+
this.notify.error(charge.data.attributes.message);
63+
}
64+
});
65+
}
66+
67+
}, this.elementId);
2468

25-
style: {
26-
label : 'pay',
27-
size : 'medium', // tiny, small, medium
28-
color : 'gold', // orange, blue, silver
29-
shape : 'pill' // pill, rect
30-
},
69+
} else if (this.paymentFor === 'invoice') {
70+
let eventInvoice = this.data;
71+
let createPayload = {
72+
'data': {
73+
'attributes': {
74+
'return-url' : `${window.location.origin}/event-invoice/${eventInvoice.identifier}/paid`,
75+
'cancel-url' : `${window.location.origin}/event-invoice/${eventInvoice.identifier}/pending`
76+
},
77+
'type': 'paypal-payment'
78+
}
79+
};
80+
paypal.Button.render({
81+
env : 'sandbox',
82+
commit : true,
3183

32-
payment: () => {
33-
return this.loader.post(`orders/${order.identifier}/create-paypal-payment`, createPayload)
34-
.then(res => {
35-
return res.payment_id;
36-
});
37-
},
84+
style: {
85+
label : 'pay',
86+
size : 'medium', // tiny, small, medium
87+
color : 'gold', // orange, blue, silver
88+
shape : 'pill' // pill, rect
89+
},
3890

39-
onAuthorize: data => {
40-
// this callback will be for authorizing the payments
41-
let chargePayload = {
42-
'data': {
43-
'attributes': {
44-
'stripe' : null,
45-
'paypal_payer_id' : data.payerID,
46-
'paypal_payment_id' : data.paymentID
47-
},
48-
'type': 'charge'
49-
}
50-
};
51-
let config = {
52-
skipDataTransform: true
53-
};
54-
chargePayload = JSON.stringify(chargePayload);
55-
return this.loader.post(`orders/${order.identifier}/charge`, chargePayload, config)
56-
.then(charge => {
57-
if (charge.data.attributes.status) {
58-
this.notify.success(charge.data.attributes.message);
59-
this.router.transitionTo('orders.view', order.identifier);
60-
} else {
61-
this.notify.error(charge.data.attributes.message);
91+
payment: () => {
92+
return this.loader.post(`event-invoices/${eventInvoice.identifier}/create-paypal-payment`, createPayload)
93+
.then(res => {
94+
return res.payment_id;
95+
});
96+
},
97+
98+
onAuthorize: data => {
99+
// this callback will be for authorizing the payments
100+
let chargePayload = {
101+
'data': {
102+
'attributes': {
103+
'stripe' : null,
104+
'paypal_payer_id' : data.payerID,
105+
'paypal_payment_id' : data.paymentID
106+
},
107+
'type': 'charge'
62108
}
63-
});
64-
}
109+
};
110+
let config = {
111+
skipDataTransform: true
112+
};
113+
chargePayload = JSON.stringify(chargePayload);
114+
return this.loader.post(`event-invoices/${eventInvoice.identifier}/charge`, chargePayload, config)
115+
.then(charge => {
116+
if (charge.status) {
117+
this.notify.success(charge.status);
118+
this.router.transitionTo('event-invoice.paid', eventInvoice.identifier);
119+
} else {
120+
this.notify.error(charge.error);
121+
}
122+
});
123+
}
124+
125+
}, this.elementId);
65126

66-
}, this.elementId);
67127

128+
}
68129
}
69130
});

app/templates/event-invoice/review.hbs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@
7070
</div>
7171
</div>
7272
</div>
73-
<button class="ui primary button" href="#">{{t 'Pay Now' }}</button>
73+
<div class='paypal-button'>
74+
{{paypal-button data=model.data paymentFor='invoice'}}
75+
</div>
7476
</div>
7577
</div>
7678
</div>

app/templates/orders/pending.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
{{/if}}
4747
{{#if isPaypal}}
4848
<div class='paypal-button'>
49-
{{paypal-button data=model.order}}
49+
{{paypal-button data=model.order paymentFor='order'}}
5050
</div>
5151
{{/if}}
5252
{{#if isOmise}}

0 commit comments

Comments
 (0)