mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Refactor form usage
This commit is contained in:
parent
639e8409c8
commit
6694c79617
1 changed files with 17 additions and 10 deletions
|
@ -166,6 +166,13 @@ class CreateOrderEndpoint implements EndpointInterface {
|
||||||
*/
|
*/
|
||||||
protected $logger;
|
protected $logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The form data, or empty if not available.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $form = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CreateOrderEndpoint constructor.
|
* CreateOrderEndpoint constructor.
|
||||||
*
|
*
|
||||||
|
@ -276,18 +283,20 @@ class CreateOrderEndpoint implements EndpointInterface {
|
||||||
|
|
||||||
$this->set_bn_code( $data );
|
$this->set_bn_code( $data );
|
||||||
|
|
||||||
$form_fields = $data['form'] ?? null;
|
if ( isset( $data['form'] ) ) {
|
||||||
|
$this->form = $data['form'];
|
||||||
|
}
|
||||||
|
|
||||||
if ( $this->early_validation_enabled
|
if ( $this->early_validation_enabled
|
||||||
&& is_array( $form_fields )
|
&& $this->form
|
||||||
&& 'checkout' === $data['context']
|
&& 'checkout' === $data['context']
|
||||||
&& in_array( $payment_method, array( PayPalGateway::ID, CardButtonGateway::ID ), true )
|
&& in_array( $payment_method, array( PayPalGateway::ID, CardButtonGateway::ID ), true )
|
||||||
) {
|
) {
|
||||||
$this->validate_form( $form_fields );
|
$this->validate_form( $this->form );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'pay-now' === $data['context'] && is_array( $form_fields ) && get_option( 'woocommerce_terms_page_id', '' ) !== '' ) {
|
if ( 'pay-now' === $data['context'] && $this->form && get_option( 'woocommerce_terms_page_id', '' ) !== '' ) {
|
||||||
$this->validate_paynow_form( $form_fields );
|
$this->validate_paynow_form( $this->form );
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -510,11 +519,9 @@ class CreateOrderEndpoint implements EndpointInterface {
|
||||||
$payer = $this->payer_factory->from_paypal_response( json_decode( wp_json_encode( $data['payer'] ) ) );
|
$payer = $this->payer_factory->from_paypal_response( json_decode( wp_json_encode( $data['payer'] ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! $payer && isset( $data['form'] ) ) {
|
if ( ! $payer && $this->form ) {
|
||||||
$form_fields = $data['form'];
|
if ( isset( $this->form['billing_email'] ) && '' !== $this->form['billing_email'] ) {
|
||||||
|
return $this->payer_factory->from_checkout_form( $this->form );
|
||||||
if ( is_array( $form_fields ) && isset( $form_fields['billing_email'] ) && '' !== $form_fields['billing_email'] ) {
|
|
||||||
return $this->payer_factory->from_checkout_form( $form_fields );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue