Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
Transpile to ES5 to make uglify to work.
Browse files Browse the repository at this point in the history
Move `currencyCode` target to `total.amount.currency`.
Better `complete` handling.
Handle exceptions for `onshippingoptionchange`.

Change-Id: Ia442d3b1fef280f5ae6737437445da5c71ba1d09
  • Loading branch information
agektmr committed May 11, 2017
1 parent cadeb7f commit f35bf1b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -21,15 +21,15 @@
"mocha": "^3.2.0",
"ts-loader": "^2.0.0",
"webpack": "^2.2.1",
"webpack-stream": "^3.2.0"
"webpack-stream": "^3.2.0",
"webpack-uglify-js-plugin": "^1.1.9"
},
"dependencies": {
"body-parser": "^1.16.1",
"express": "^4.14.0",
"fs": "^0.0.1-security",
"path": "^0.12.7",
"request": "^2.79.0",
"webpack-uglify-js-plugin": "^1.1.9",
"whatwg-fetch": "^2.0.2"
}
}
30 changes: 20 additions & 10 deletions src/index.ts
Expand Up @@ -136,13 +136,9 @@ if (ApplePaySession) {
* @param {PaymentDetails} details
*/
private updatePaymentDetails(details: PaymentDetails) {
let codes = false;
if (details.displayItems) {
this.paymentRequest.lineItems = [];
this.paymentRequest.lineItems = <ApplePayJS.ApplePayLineItem[]>[];
for (let item of details.displayItems) {
if (!codes) {
this.paymentRequest.currencyCode = item.amount.currency;
}
let lineItem: ApplePayJS.ApplePayLineItem = {
type: item.pending === true ? 'pending' : 'final',
label: item.label,
Expand All @@ -166,11 +162,14 @@ if (ApplePaySession) {
}

if (details.total) {
this.paymentRequest.currencyCode = details.total.amount.currency;
this.paymentRequest.total = {
type: details.total.pending === true ? 'pending' : 'final',
label: details.total.label,
amount: details.total.amount.value
};
} else {
throw '`total` is required parameter for `PaymentDetails`.';
}
}

Expand Down Expand Up @@ -351,7 +350,6 @@ if (ApplePaySession) {
this.paymentRequest.lineItems);
}, (details: PaymentDetails) => {
// TODO: In which case does this happen?
// https://developer.apple.com/reference/applepayjs/applepaysession/1778008-completeshippingcontactselection
this.updatePaymentDetails(details);
this.session.completeShippingContactSelection(
ApplePaySession.STATUS_FAILURE,
Expand Down Expand Up @@ -387,6 +385,14 @@ if (ApplePaySession) {
ApplePaySession.STATUS_SUCCESS,
this.paymentRequest.total,
this.paymentRequest.lineItems);
}, (details: PaymentDetails) => {
// TODO: In which case does this happen?
this.updatePaymentDetails(details);
this.session.completeShippingMethodSelection(
ApplePaySession.STATUS_FAILURE,
null,
null
);
});
}
})
Expand Down Expand Up @@ -425,7 +431,8 @@ if (ApplePaySession) {
private onPaymentComplete(result: 'success' | 'fail' | 'unknown'): void {
if (result === 'success' ||
result === 'fail' ||
result === 'unknown') {
result === 'unknown' ||
result === '') {
let status: number;
switch (result) {
case 'success':
Expand All @@ -435,11 +442,14 @@ if (ApplePaySession) {
status = ApplePaySession.STATUS_FAILURE;
break;
case 'unknown':
// TODO: What to do if dev indicates 'unknown'?
status = ApplePaySession.STATUS_FAILURE;
// TODO: Not sure what is the best way to handle this
// Treat is as success for the time being.
status = ApplePaySession.STATUS_SUCCESS;
break;
default:
status = ApplePaySession.STATUS_FAILURE;
// TODO: Not sure what is the best way to handle this
// Treat is as success for the time being.
status = ApplePaySession.STATUS_SUCCESS;
break;
}
// https://developer.apple.com/reference/applepayjs/applepaysession/1778012-completepayment
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Expand Up @@ -19,7 +19,7 @@
"removeComments": true,
"sourceMap": true,
"allowJs": true,
"target": "es6",
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
Expand Down
4 changes: 1 addition & 3 deletions webpack.config.js
Expand Up @@ -28,8 +28,6 @@ module.exports = {
}]
},
plugins: [
// new webpack.optimize.UglifyJsPlugin({
// sourceMap: true
// })
new webpack.optimize.UglifyJsPlugin()
]
};

0 comments on commit f35bf1b

Please sign in to comment.