From f35bf1b0a8f8506689f122ca961e91d8935de0d2 Mon Sep 17 00:00:00 2001 From: Eiji Kitamura Date: Thu, 11 May 2017 14:38:09 +0900 Subject: [PATCH] Transpile to ES5 to make uglify to work. Move `currencyCode` target to `total.amount.currency`. Better `complete` handling. Handle exceptions for `onshippingoptionchange`. Change-Id: Ia442d3b1fef280f5ae6737437445da5c71ba1d09 --- package.json | 4 ++-- src/index.ts | 30 ++++++++++++++++++++---------- tsconfig.json | 2 +- webpack.config.js | 4 +--- 4 files changed, 24 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 8dbcd45..862cd5d 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,8 @@ "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", @@ -29,7 +30,6 @@ "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" } } diff --git a/src/index.ts b/src/index.ts index 176bb9e..fe585c0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 = []; 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, @@ -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`.'; } } @@ -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, @@ -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 + ); }); } }) @@ -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': @@ -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 diff --git a/tsconfig.json b/tsconfig.json index 9679a3f..86152f3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,7 +19,7 @@ "removeComments": true, "sourceMap": true, "allowJs": true, - "target": "es6", + "target": "es5", "typeRoots": [ "node_modules/@types" ], diff --git a/webpack.config.js b/webpack.config.js index 08e2da3..c4a9c46 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -28,8 +28,6 @@ module.exports = { }] }, plugins: [ - // new webpack.optimize.UglifyJsPlugin({ - // sourceMap: true - // }) + new webpack.optimize.UglifyJsPlugin() ] }; \ No newline at end of file