/** * External dependencies */ import { __ } from '@wordpress/i18n'; import { Component, Fragment } from '@wordpress/element'; import { Button } from '@wordpress/components'; import interpolateComponents from 'interpolate-components'; import { compose } from '@wordpress/compose'; import { withDispatch, withSelect } from '@wordpress/data'; import { Form, Link, Stepper, TextControl } from '@woocommerce/components'; import { OPTIONS_STORE_NAME } from '@woocommerce/data'; class PayFast extends Component { getInitialConfigValues = () => { return { merchant_id: '', merchant_key: '', pass_phrase: '', }; }; validate = ( values ) => { const errors = {}; if ( ! values.merchant_id ) { errors.merchant_id = __( 'Please enter your merchant ID', 'woocommerce-admin' ); } if ( ! values.merchant_key ) { errors.merchant_key = __( 'Please enter your merchant key', 'woocommerce-admin' ); } if ( ! values.pass_phrase ) { errors.pass_phrase = __( 'Please enter your passphrase', 'woocommerce-admin' ); } return errors; }; updateSettings = async ( values ) => { const { updateOptions, createNotice, markConfigured } = this.props; // Because the PayFast extension only works with the South African Rand // currency, force the store to use it while setting the PayFast settings const update = await updateOptions( { woocommerce_currency: 'ZAR', woocommerce_payfast_settings: { merchant_id: values.merchant_id, merchant_key: values.merchant_key, pass_phrase: values.pass_phrase, enabled: 'yes', }, } ); if ( update.success ) { markConfigured( 'payfast' ); createNotice( 'success', __( 'PayFast connected successfully', 'woocommerce-admin' ) ); } else { createNotice( 'error', __( 'There was a problem saving your payment setings', 'woocommerce-admin' ) ); } }; renderConnectStep() { const { isOptionsRequesting } = this.props; const helpText = interpolateComponents( { mixedString: __( 'Your API details can be obtained from your {{link}}PayFast account{{/link}}', 'woocommerce-admin' ), components: { link: ( ), }, } ); return (
{ ( { getInputProps, handleSubmit } ) => { return (

{ helpText }

); } }
); } render() { const { installStep, isOptionsRequesting } = this.props; return ( ); } } export default compose( withSelect( ( select ) => { const { isOptionsUpdating } = select( OPTIONS_STORE_NAME ); const isOptionsRequesting = isOptionsUpdating(); return { isOptionsRequesting, }; } ), withDispatch( ( dispatch ) => { const { createNotice } = dispatch( 'core/notices' ); const { updateOptions } = dispatch( OPTIONS_STORE_NAME ); return { createNotice, updateOptions, }; } ) )( PayFast );