2020-01-06 22:28:09 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { assertConfigHasProperties, assertValidElement } from './assertions';
|
|
|
|
|
|
|
|
export default class ExpressPaymentMethodConfig {
|
|
|
|
constructor( config ) {
|
|
|
|
// validate config
|
|
|
|
ExpressPaymentMethodConfig.assertValidConfig( config );
|
|
|
|
this.id = config.id;
|
2020-03-30 12:07:49 +00:00
|
|
|
this.content = config.content;
|
2020-03-10 16:35:30 +00:00
|
|
|
this.edit = config.edit;
|
2020-01-06 22:28:09 +00:00
|
|
|
this.canMakePayment = config.canMakePayment;
|
|
|
|
}
|
|
|
|
|
|
|
|
static assertValidConfig = ( config ) => {
|
2020-03-30 12:07:49 +00:00
|
|
|
assertConfigHasProperties( config, [ 'id', 'content', 'edit' ] );
|
2020-01-06 22:28:09 +00:00
|
|
|
if ( typeof config.id !== 'string' ) {
|
|
|
|
throw new TypeError(
|
|
|
|
'The id for the express payment method must be a string'
|
|
|
|
);
|
|
|
|
}
|
2020-03-30 12:07:49 +00:00
|
|
|
assertValidElement( config.content, 'content' );
|
2020-03-10 16:35:30 +00:00
|
|
|
assertValidElement( config.edit, 'edit' );
|
2020-04-09 11:44:29 +00:00
|
|
|
if ( typeof config.canMakePayment !== 'function' ) {
|
2020-01-06 22:28:09 +00:00
|
|
|
throw new TypeError(
|
2020-04-09 11:44:29 +00:00
|
|
|
'The canMakePayment property for the express payment method must be a function.'
|
2020-01-06 22:28:09 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|