41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
/**
|
|
* Internal dependencies
|
|
*/
|
|
import { assertConfigHasProperties, assertValidElement } from './assertions';
|
|
|
|
export default class ExpressPaymentMethodConfig {
|
|
constructor( config ) {
|
|
// validate config
|
|
ExpressPaymentMethodConfig.assertValidConfig( config );
|
|
this.name = config.name;
|
|
this.content = config.content;
|
|
this.edit = config.edit;
|
|
this.canMakePayment = config.canMakePayment;
|
|
this.paymentMethodId = config.paymentMethodId || this.name;
|
|
}
|
|
|
|
static assertValidConfig = ( config ) => {
|
|
assertConfigHasProperties( config, [ 'name', 'content', 'edit' ] );
|
|
if ( typeof config.name !== 'string' ) {
|
|
throw new TypeError(
|
|
'The name property for the express payment method must be a string'
|
|
);
|
|
}
|
|
if (
|
|
typeof config.paymentMethodId !== 'string' &&
|
|
typeof config.paymentMethodId !== 'undefined'
|
|
) {
|
|
throw new Error(
|
|
'The paymentMethodId property for the payment method must be a string or undefined (in which case it will be the value of the name property).'
|
|
);
|
|
}
|
|
assertValidElement( config.content, 'content' );
|
|
assertValidElement( config.edit, 'edit' );
|
|
if ( typeof config.canMakePayment !== 'function' ) {
|
|
throw new TypeError(
|
|
'The canMakePayment property for the express payment method must be a function.'
|
|
);
|
|
}
|
|
};
|
|
}
|