Skip to content

Instantly share code, notes, and snippets.

@mitchlloyd
Created January 13, 2017 20:53
Show Gist options
  • Save mitchlloyd/a50efc51b772ee9a49cd6263eee65f1b to your computer and use it in GitHub Desktop.
Save mitchlloyd/a50efc51b772ee9a49cd6263eee65f1b to your computer and use it in GitHub Desktop.
export default Component.extend({
actions: {
beginApplePay() {
let item = this.get('item');
let price = item.get('price');
let paymentRequest = {
requiredShippingContactFields: ['email', 'postalAddress'],
countryCode: 'US',
currencyCode: 'USD',
total: {
label: 'Stripe.com',
amount: price / 100 + ''
}
};
// Stripe.applePay.buildSession(...) - A seam!
let session = Stripe.applePay.buildSession(paymentRequest, (result, completion) => {
this.get('onChargeSuccess')({
shippingContact: result.shippingContact,
token: result.token.id,
price,
item,
description: `201 Created Sticker: ${item.get('name')}`
}).then(() => {
trySet(this, 'successMessage', 'Purchase is on its way');
// Looks like another seam
completion(ApplePaySession.STATUS_SUCCESS);
}).catch(() => {
trySet('errorMessage', 'Purchase failed');
// Another one
completion(ApplePaySession.STATUS_FAILURE);
});
}, (error) => {
trySet(this, 'errorMessage', error.message);
});
// Another third-party API
session.begin();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment