react-payment-request-api
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e(t["react-payment-request-api"]=t["react-payment-request-api"]||{},t.React)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function r(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&(n[r[o]]=t[r[o]]);return n}var o,i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},u=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},c=function(t){var e=t.reduce(function(t,e){if(e.supportedMethods&&"basic-card"===e.supportedMethods[0]){var n=e;if(n.data)return{supportedMethods:n.data.supportedNetworks}}return t},null);return e?[e].concat(t):t.slice()},p=function(){return!!window.PaymentRequest},a=function(t,e,n){n&&t.addEventListener(e,function(e){return e.updateWith(new Promise(function(e,r){return n(t,e,r)}))})},s=function(){return o.abort()},f=function(t){return function(){o=new PaymentRequest(c(t.methodData),t.details,t.options||{}),a(o,"shippingaddresschange",t.onShippingAddressChange),a(o,"shippingoptionchange",t.onShippingOptionChange),o.show().then(function(e){return new Promise(function(n,r){return t.onShowSuccess(e,n,r)}).then(function(){return e.complete("success")}).catch(function(){return e.complete("fail")})}).catch(function(e){return t.onShowFail(e)})}},d=function(){return function(t){return function(o){function i(){return null!==o&&o.apply(this,arguments)||this}return n(i,o),i.prototype.render=function(){var n=this.props,o=n.config,i=r(n,["config"]);return p()&&o?e.createElement(t,u({},i,{isSupported:!0,show:f(o),abort:s})):e.createElement(t,u({},i,{isSupported:!1}))},i}(e.Component)}};t.default=d,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e(t["react-payment-request-api"]=t["react-payment-request-api"]||{},t.React)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function r(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&(n[r[o]]=t[r[o]]);return n}var o,i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},u=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},c=function(t){var e=t.reduce(function(t,e){if(e.supportedMethods&&"basic-card"===e.supportedMethods[0]){var n=e;if(n.data&&n.data.supportedNetworks)return{supportedMethods:n.data.supportedNetworks}}return t},null);return e?[e].concat(t):t.slice()},p=function(){return!!window.PaymentRequest},a=function(t,e,n){n&&t.addEventListener(e,function(e){return e.updateWith(new Promise(function(e,r){return n(t,e,r)}))})},s=function(){return o.abort()},f=function(t){return function(){o=new PaymentRequest(c(t.methodData),t.details,t.options||{}),a(o,"shippingaddresschange",t.onShippingAddressChange),a(o,"shippingoptionchange",t.onShippingOptionChange),o.show().then(function(e){return new Promise(function(n,r){return t.onShowSuccess(e,n,r)}).then(function(){return e.complete("success")}).catch(function(){return e.complete("fail")})}).catch(function(e){return t.onShowFail(e)})}};t.default=function(){return function(t){return function(o){function i(){return null!==o&&o.apply(this,arguments)||this}return n(i,o),i.prototype.render=function(){var n=this.props,o=n.config,i=r(n,["config"]),c=p(),a=c&&o?{isSupported:c,abort:s,show:f(o)}:{isSupported:c};return e.createElement(t,u({},i,a))},i}(e.Component)}},Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -10,3 +10,6 @@ { | ||
], | ||
"testRegex": "./src/.*\\.test\\.(ts|tsx|js)$" | ||
"testRegex": "./src/.*\\.test\\.(ts|tsx|js)$", | ||
"collectCoverage": true, | ||
"collectCoverageFrom": ["src/paymentRequest.tsx", "src/normalizeInstrumentations.ts"], | ||
"mapCoverage": true | ||
} |
@@ -8,3 +8,3 @@ "use strict"; | ||
var basicCardPaymentMethodData = paymentMethodData; | ||
if (basicCardPaymentMethodData.data) { | ||
if (basicCardPaymentMethodData.data && !!basicCardPaymentMethodData.data.supportedNetworks) { | ||
return { supportedMethods: basicCardPaymentMethodData.data.supportedNetworks }; | ||
@@ -11,0 +11,0 @@ } |
@@ -1,7 +0,5 @@ | ||
import * as React from 'react'; | ||
import { AnyComponent } from './utils'; | ||
import { PaymentRequestParamsConfig, PaymentRequestParams } from './types'; | ||
import { PaymentRequestParams } from './types'; | ||
export declare const abort: () => Promise<void>; | ||
export declare const show: (params: PaymentRequestParams) => () => void; | ||
declare const paymentRequest: <TProps extends Object>() => (WrappedComponent: AnyComponent<TProps, any>) => React.ComponentClass<TProps & PaymentRequestParamsConfig>; | ||
declare const paymentRequest: <TProps extends object>() => (WrappedComponent: any) => any; | ||
export default paymentRequest; |
/// <reference types="jest" /> | ||
import { PaymentRequestParams } from './index'; | ||
declare const getConfig: (onShowFail?: jest.Mock<{}> | undefined) => PaymentRequestParams; | ||
declare const getConfig: (onShowFail?: jest.Mock<{}> | undefined, removeOptions?: boolean | undefined) => PaymentRequestParams; | ||
export default getConfig; |
@@ -7,3 +7,3 @@ "use strict"; | ||
}; | ||
var getConfig = function (onShowFail) { return ({ | ||
var getConfig = function (onShowFail, removeOptions) { return ({ | ||
methodData: [{ | ||
@@ -16,3 +16,3 @@ supportedMethods: ['basic-card'], | ||
details: details, | ||
options: { | ||
options: removeOptions ? undefined : { | ||
requestShipping: true, | ||
@@ -19,0 +19,0 @@ }, |
@@ -33,3 +33,3 @@ "use strict"; | ||
var request; | ||
var isSupported = function () { return !!window.PaymentRequest; }; | ||
var hasSupport = function () { return !!window.PaymentRequest; }; | ||
var addEventListener = function (requestListener, event, callback) { | ||
@@ -61,7 +61,8 @@ if (!!callback) { | ||
ExtendedComponent.prototype.render = function () { | ||
var _a = this.props, config = _a.config, rest = __rest(_a, ["config"]); | ||
if (!isSupported() || !config) { | ||
return React.createElement(WrappedComponent, __assign({}, rest, { isSupported: false })); | ||
} | ||
return (React.createElement(WrappedComponent, __assign({}, rest, { isSupported: true, show: exports.show(config), abort: exports.abort }))); | ||
var _a = this.props, config = _a.config, passedProps = __rest(_a, ["config"]); | ||
var isSupported = hasSupport(); | ||
var supportedProps = isSupported && config | ||
? { isSupported: isSupported, abort: exports.abort, show: exports.show(config) } | ||
: { isSupported: isSupported }; | ||
return React.createElement(WrappedComponent, __assign({}, passedProps, supportedProps)); | ||
}; | ||
@@ -68,0 +69,0 @@ return ExtendedComponent; |
{ | ||
"name": "react-payment-request-api", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "React high order component that expose the payment request api", | ||
@@ -40,4 +40,4 @@ "main": "lib/index.js", | ||
"@types/jest": "^19.2.3", | ||
"@types/react": "^15.0.25", | ||
"@types/react-dom": "^15.5.0", | ||
"@types/react": "^15.0.34", | ||
"@types/react-dom": "^15.5.1", | ||
"enzyme": "^2.8.2", | ||
@@ -57,3 +57,3 @@ "jest": "^20.0.1", | ||
"tslint-react": "^3.0.0", | ||
"typescript": "^2.3" | ||
"typescript": "^2.4.0" | ||
}, | ||
@@ -60,0 +60,0 @@ "dependencies": { |
@@ -26,3 +26,3 @@ <p align="center"> | ||
At the moment the [payment request api](https://developers.google.com/web/fundamentals/getting-started/primers/payment-request/) is supported on Chrome for Android and Android Webview v. ^53.0. | ||
[Payment request api](https://developers.google.com/web/fundamentals/getting-started/primers/payment-request/) is supported on Chrome for desktop v. ^60.0, Chrome for Android and Android Webview v. ^53.0, Microsoft Edge v. ^15.0. | ||
@@ -29,0 +29,0 @@ ## Demo |
@@ -14,3 +14,3 @@ import normalizeInstrumentations from './normalizeInstrumentations'; | ||
describe('when instrumentations contains basicCard but no supportedNetworks', () => { | ||
it('should return the same instrumentations', () => { | ||
it('should return the same instrumentations when no data is defined', () => { | ||
const instrumentations = [{ | ||
@@ -22,2 +22,10 @@ supportedMethods: ['basic-card'], | ||
}); | ||
it('should return the same instrumentations when data is empty', () => { | ||
const instrumentations = [{ | ||
supportedMethods: ['basic-card'], | ||
data: {}, | ||
}] as PaymentMethodData[]; | ||
expect(normalizeInstrumentations(instrumentations)).toEqual(instrumentations); | ||
}); | ||
}); | ||
@@ -24,0 +32,0 @@ |
@@ -6,3 +6,3 @@ export default (methodData: PaymentMethodData[]) => { | ||
const basicCardPaymentMethodData = paymentMethodData; | ||
if (basicCardPaymentMethodData.data) { | ||
if (basicCardPaymentMethodData.data && !!basicCardPaymentMethodData.data.supportedNetworks) { | ||
return { supportedMethods: basicCardPaymentMethodData.data.supportedNetworks }; | ||
@@ -9,0 +9,0 @@ } |
@@ -8,3 +8,3 @@ import { PaymentRequestParams } from './index'; | ||
const getConfig = (onShowFail?: jest.Mock<{}>) => ({ | ||
const getConfig = (onShowFail?: jest.Mock<{}>, removeOptions?: boolean) => ({ | ||
methodData: [{ | ||
@@ -17,3 +17,3 @@ supportedMethods: ['basic-card'], | ||
details: details, | ||
options: { | ||
options: removeOptions ? undefined : { | ||
requestShipping: true, | ||
@@ -20,0 +20,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
42737
1.21%698
0.43%33
-10.81%