2020-01-06 22:28:09 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { assertConfigHasProperties, assertValidElement } from './assertions';
|
|
|
|
|
|
|
|
export default class PaymentMethodConfig {
|
|
|
|
constructor( config ) {
|
|
|
|
// validate config
|
|
|
|
PaymentMethodConfig.assertValidConfig( config );
|
|
|
|
this.id = config.id;
|
|
|
|
this.label = config.label;
|
|
|
|
this.ariaLabel = config.ariaLabel;
|
|
|
|
this.activeContent = config.activeContent;
|
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 ) => {
|
|
|
|
assertConfigHasProperties( config, [
|
|
|
|
'id',
|
|
|
|
'label',
|
|
|
|
'stepContent',
|
|
|
|
'ariaLabel',
|
|
|
|
'activeContent',
|
2020-03-10 16:35:30 +00:00
|
|
|
'edit',
|
2020-01-06 22:28:09 +00:00
|
|
|
'canMakePayment',
|
|
|
|
] );
|
|
|
|
if ( typeof config.id !== 'string' ) {
|
|
|
|
throw new Error( 'The id for the payment method must be a string' );
|
|
|
|
}
|
|
|
|
assertValidElement( config.label, 'label' );
|
|
|
|
assertValidElement( config.stepContent, 'stepContent' );
|
|
|
|
assertValidElement( config.activeContent, 'activeContent' );
|
2020-03-10 16:35:30 +00:00
|
|
|
assertValidElement( config.edit, 'edit' );
|
2020-01-06 22:28:09 +00:00
|
|
|
if ( typeof config.ariaLabel !== 'string' ) {
|
|
|
|
throw new TypeError(
|
|
|
|
'The ariaLabel for the payment method must be a string'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( ! ( config.canMakePayment instanceof Promise ) ) {
|
|
|
|
throw new TypeError(
|
|
|
|
'The canMakePayment property for the payment method must be a promise.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|