mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Ensure email exist otherwise do not return payer object
This commit is contained in:
parent
99413d3652
commit
0947031c3f
2 changed files with 44 additions and 12 deletions
|
@ -149,22 +149,51 @@ class PayerFactory {
|
|||
);
|
||||
}
|
||||
|
||||
public function from_checkout_form(array $data) {
|
||||
/**
|
||||
* Returns a Payer object based off the given checkout form fields.
|
||||
*
|
||||
* @param array $form_fields The checkout form fields.
|
||||
* @return Payer
|
||||
*/
|
||||
public function from_checkout_form( array $form_fields ): Payer {
|
||||
|
||||
$first_name = $data['billing_first_name'] ?? '';
|
||||
$last_name = $data['billing_last_name'] ?? '';
|
||||
$billing_email = $data['billing_email'] ?? '';
|
||||
$billing_country = $data['billing_country'] ?? '';
|
||||
$billing_address_1 = $data['billing_address_1'] ?? '';
|
||||
$first_name = $form_fields['billing_first_name'] ?? '';
|
||||
$last_name = $form_fields['billing_last_name'] ?? '';
|
||||
$billing_email = $form_fields['billing_email'] ?? '';
|
||||
$billing_country = $form_fields['billing_country'] ?? '';
|
||||
$billing_address_1 = $form_fields['billing_address_1'] ?? '';
|
||||
$billing_address_2 = $form_fields['billing_address_2'] ?? '';
|
||||
$admin_area_1 = $form_fields['billing_state'] ?? '';
|
||||
$admin_area_2 = $form_fields['billing_city'] ?? '';
|
||||
$billing_postcode = $form_fields['billing_postcode'] ?? '';
|
||||
|
||||
$phone = null;
|
||||
if ( isset( $form_fields['billing_phone'] ) && '' !== $form_fields['billing_phone'] ) {
|
||||
// make sure the phone number contains only numbers and is max 14. chars long.
|
||||
$national_number = $form_fields['billing_phone'];
|
||||
$national_number = preg_replace( '/[^0-9]/', '', $national_number );
|
||||
$national_number = substr( $national_number, 0, 14 );
|
||||
|
||||
$phone = new PhoneWithType(
|
||||
'HOME',
|
||||
new Phone( $national_number )
|
||||
);
|
||||
}
|
||||
|
||||
return new Payer(
|
||||
new PayerName($first_name, $last_name),
|
||||
new PayerName( $first_name, $last_name ),
|
||||
$billing_email,
|
||||
'',
|
||||
new Address(
|
||||
$billing_country,
|
||||
$billing_address_1
|
||||
)
|
||||
$billing_address_1,
|
||||
$billing_address_2,
|
||||
$admin_area_1,
|
||||
$admin_area_2,
|
||||
$billing_postcode
|
||||
),
|
||||
null,
|
||||
$phone
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -340,9 +340,12 @@ class CreateOrderEndpoint implements EndpointInterface {
|
|||
$payer = $this->payer_factory->from_paypal_response( json_decode( wp_json_encode( $data['payer'] ) ) );
|
||||
}
|
||||
|
||||
if(!$payer && isset($data['form'])) {
|
||||
parse_str($data['form'], $output);
|
||||
return $this->payer_factory->from_checkout_form($output);
|
||||
if ( ! $payer && isset( $data['form'] ) ) {
|
||||
parse_str( $data['form'], $form_fields );
|
||||
|
||||
if ( isset( $form_fields['billing_email'] ) && '' !== $form_fields['billing_email'] ) {
|
||||
return $this->payer_factory->from_checkout_form( $form_fields );
|
||||
}
|
||||
}
|
||||
|
||||
return $payer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue