pay-now-scenario.js
104 lines
| 1 | const { compose } = wp.compose; |
| 2 | |
| 3 | const { |
| 4 | withSelect, |
| 5 | withDispatch, |
| 6 | } = wp.data; |
| 7 | |
| 8 | const { |
| 9 | TextControl, |
| 10 | SelectControl, |
| 11 | BaseControl, |
| 12 | RadioControl, |
| 13 | } = wp.components; |
| 14 | |
| 15 | const { |
| 16 | withSelectFormFields, |
| 17 | withSelectGateways, |
| 18 | withDispatchGateways, |
| 19 | withSelectActionsByType, |
| 20 | } = JetFBHooks; |
| 21 | |
| 22 | const { GatewayFetchButton } = JetFBComponents; |
| 23 | |
| 24 | function PayNowScenario( { |
| 25 | gatewayGeneral, |
| 26 | gatewaySpecific, |
| 27 | setGateway, |
| 28 | setGatewaySpecific, |
| 29 | formFields, |
| 30 | getSpecificOrGlobal, |
| 31 | loadingGateway, |
| 32 | scenarioSource, |
| 33 | noticeOperations, |
| 34 | scenarioLabel, |
| 35 | globalGatewayLabel, |
| 36 | } ) { |
| 37 | |
| 38 | const displayNotice = status => response => { |
| 39 | noticeOperations.removeNotice( gatewayGeneral.gateway ); |
| 40 | noticeOperations.createNotice( { |
| 41 | status, |
| 42 | content: response.message, |
| 43 | id: gatewayGeneral.gateway, |
| 44 | } ); |
| 45 | }; |
| 46 | |
| 47 | return <> |
| 48 | <BaseControl |
| 49 | label={ scenarioLabel( 'fetch_button_label' ) } |
| 50 | > |
| 51 | <div className="jet-user-fields-map__list"> |
| 52 | { ( ! loadingGateway.success && ! loadingGateway.loading ) && <span |
| 53 | className={ 'description-controls' } |
| 54 | > |
| 55 | { scenarioLabel( 'fetch_button_help' ) } |
| 56 | </span> } |
| 57 | <GatewayFetchButton |
| 58 | initialLabel={ scenarioLabel( 'fetch_button' ) } |
| 59 | label={ scenarioLabel( 'fetch_button_retry' ) } |
| 60 | apiArgs={ { |
| 61 | ...scenarioSource.fetch, |
| 62 | data: { |
| 63 | client_id: getSpecificOrGlobal( 'client_id' ), |
| 64 | secret: getSpecificOrGlobal( 'secret' ), |
| 65 | }, |
| 66 | } } |
| 67 | onFail={ displayNotice( 'error' ) } |
| 68 | /> |
| 69 | </div> |
| 70 | </BaseControl> |
| 71 | { loadingGateway.success && <> |
| 72 | <TextControl |
| 73 | label={ scenarioLabel( 'currency' ) } |
| 74 | key='paypal_currency_code_setting' |
| 75 | value={ gatewaySpecific.currency } |
| 76 | onChange={ currency => setGatewaySpecific( { currency } ) } |
| 77 | /> |
| 78 | <SelectControl |
| 79 | label={ globalGatewayLabel( 'price_field' ) } |
| 80 | key={ 'form_fields_price_field' } |
| 81 | value={ gatewayGeneral.price_field } |
| 82 | labelPosition='side' |
| 83 | onChange={ price_field => { |
| 84 | setGateway( { price_field } ); |
| 85 | } } |
| 86 | options={ formFields } |
| 87 | /> |
| 88 | </> } |
| 89 | </>; |
| 90 | } |
| 91 | |
| 92 | export default compose( |
| 93 | withSelect( ( ...props ) => ( |
| 94 | { |
| 95 | ...withSelectFormFields( [], '--' )( ...props ), |
| 96 | ...withSelectGateways( ...props ), |
| 97 | } |
| 98 | ) ), |
| 99 | withDispatch( ( ...props ) => ( |
| 100 | { |
| 101 | ...withDispatchGateways( ...props ), |
| 102 | } |
| 103 | ) ), |
| 104 | )( PayNowScenario ); |