Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 110 additions & 49 deletions app/components/paypal-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,123 @@ export default Component.extend({

async didInsertElement() {
this._super(...arguments);
let order = this.data;
let createPayload = {
'data': {
'attributes': {
'return-url' : `${window.location.origin}/orders/${order.identifier}/view`,
'cancel-url' : `${window.location.origin}/orders/${order.identifier}/pending`
if (this.paymentFor === 'order') {
let order = this.data;
let createPayload = {
'data': {
'attributes': {
'return-url' : `${window.location.origin}/orders/${order.identifier}/view`,
'cancel-url' : `${window.location.origin}/orders/${order.identifier}/pending`
},
'type': 'paypal-payment'
}
};

paypal.Button.render({
commit: true,

style: {
label : 'pay',
size : 'medium', // tiny, small, medium
color : 'gold', // orange, blue, silver
shape : 'pill' // pill, rect
},
'type': 'paypal-payment'
}
};

paypal.Button.render({
commit: true,
payment: () => {
return this.loader.post(`orders/${order.identifier}/create-paypal-payment`, createPayload)
.then(res => {
return res.payment_id;
});
},

onAuthorize: data => {
// this callback will be for authorizing the payments
let chargePayload = {
'data': {
'attributes': {
'stripe' : null,
'paypal_payer_id' : data.payerID,
'paypal_payment_id' : data.paymentID
},
'type': 'charge'
}
};
let config = {
skipDataTransform: true
};
chargePayload = JSON.stringify(chargePayload);
return this.loader.post(`orders/${order.identifier}/charge`, chargePayload, config)
.then(charge => {
if (charge.data.attributes.status) {
this.notify.success(charge.data.attributes.message);
this.router.transitionTo('orders.view', order.identifier);
} else {
this.notify.error(charge.data.attributes.message);
}
});
}

}, this.elementId);

style: {
label : 'pay',
size : 'medium', // tiny, small, medium
color : 'gold', // orange, blue, silver
shape : 'pill' // pill, rect
},
} else if (this.paymentFor === 'invoice') {
let eventInvoice = this.data;
let createPayload = {
'data': {
'attributes': {
'return-url' : `${window.location.origin}/event-invoice/${eventInvoice.identifier}/paid`,
'cancel-url' : `${window.location.origin}/event-invoice/${eventInvoice.identifier}/pending`
},
'type': 'paypal-payment'
}
};
paypal.Button.render({
env : 'sandbox',
commit : true,

payment: () => {
return this.loader.post(`orders/${order.identifier}/create-paypal-payment`, createPayload)
.then(res => {
return res.payment_id;
});
},
style: {
label : 'pay',
size : 'medium', // tiny, small, medium
color : 'gold', // orange, blue, silver
shape : 'pill' // pill, rect
},

onAuthorize: data => {
// this callback will be for authorizing the payments
let chargePayload = {
'data': {
'attributes': {
'stripe' : null,
'paypal_payer_id' : data.payerID,
'paypal_payment_id' : data.paymentID
},
'type': 'charge'
}
};
let config = {
skipDataTransform: true
};
chargePayload = JSON.stringify(chargePayload);
return this.loader.post(`orders/${order.identifier}/charge`, chargePayload, config)
.then(charge => {
if (charge.data.attributes.status) {
this.notify.success(charge.data.attributes.message);
this.router.transitionTo('orders.view', order.identifier);
} else {
this.notify.error(charge.data.attributes.message);
payment: () => {
return this.loader.post(`event-invoices/${eventInvoice.identifier}/create-paypal-payment`, createPayload)
.then(res => {
return res.payment_id;
});
},

onAuthorize: data => {
// this callback will be for authorizing the payments
let chargePayload = {
'data': {
'attributes': {
'stripe' : null,
'paypal_payer_id' : data.payerID,
'paypal_payment_id' : data.paymentID
},
'type': 'charge'
}
});
}
};
let config = {
skipDataTransform: true
};
chargePayload = JSON.stringify(chargePayload);
return this.loader.post(`event-invoices/${eventInvoice.identifier}/charge`, chargePayload, config)
.then(charge => {
if (charge.status) {
this.notify.success(charge.status);
this.router.transitionTo('event-invoice.paid', eventInvoice.identifier);
} else {
this.notify.error(charge.error);
}
});
}

}, this.elementId);

}, this.elementId);

}
}
});
4 changes: 3 additions & 1 deletion app/templates/event-invoice/review.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@
</div>
</div>
</div>
<button class="ui primary button" href="#">{{t 'Pay Now' }}</button>
<div class='paypal-button'>
{{paypal-button data=model.data paymentFor='invoice'}}
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/orders/pending.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
{{/if}}
{{#if isPaypal}}
<div class='paypal-button'>
{{paypal-button data=model.order}}
{{paypal-button data=model.order paymentFor='order'}}
</div>
{{/if}}
{{#if isOmise}}
Expand Down