mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
drop address from payer when country format is not correct
This commit is contained in:
parent
8fbffbced0
commit
380e4827df
3 changed files with 16 additions and 8 deletions
|
@ -70,7 +70,7 @@ class Payer {
|
|||
* @param PayerName $name The name.
|
||||
* @param string $email_address The email.
|
||||
* @param string $payer_id The payer id.
|
||||
* @param Address $address The address.
|
||||
* @param Address|null $address The address.
|
||||
* @param \DateTime|null $birthdate The birth date.
|
||||
* @param PhoneWithType|null $phone The phone.
|
||||
* @param PayerTaxInfo|null $tax_info The tax info.
|
||||
|
@ -79,7 +79,7 @@ class Payer {
|
|||
PayerName $name,
|
||||
string $email_address,
|
||||
string $payer_id,
|
||||
Address $address,
|
||||
Address $address = null,
|
||||
\DateTime $birthdate = null,
|
||||
PhoneWithType $phone = null,
|
||||
PayerTaxInfo $tax_info = null
|
||||
|
@ -133,9 +133,9 @@ class Payer {
|
|||
/**
|
||||
* Returns the address.
|
||||
*
|
||||
* @return Address
|
||||
* @return Address|null
|
||||
*/
|
||||
public function address(): Address {
|
||||
public function address() {
|
||||
return $this->address;
|
||||
}
|
||||
|
||||
|
@ -166,8 +166,13 @@ class Payer {
|
|||
$payer = array(
|
||||
'name' => $this->name()->to_array(),
|
||||
'email_address' => $this->email_address(),
|
||||
'address' => $this->address()->to_array(),
|
||||
);
|
||||
if ( $this->address() ) {
|
||||
$payer['address'] = $this->address->to_array();
|
||||
if ( 2 !== strlen( $this->address()->country_code() ) ) {
|
||||
unset( $payer['address'] );
|
||||
}
|
||||
}
|
||||
if ( $this->payer_id() ) {
|
||||
$payer['payer_id'] = $this->payer_id();
|
||||
}
|
||||
|
|
|
@ -116,7 +116,10 @@ class PayerFactory {
|
|||
* @return Payer
|
||||
*/
|
||||
public function from_paypal_response( \stdClass $data ): Payer {
|
||||
$address = $this->address_factory->from_paypal_response( $data->address );
|
||||
$address = null;
|
||||
if ( isset( $data->address ) ) {
|
||||
$address = $this->address_factory->from_paypal_response( $data->address );
|
||||
}
|
||||
$payer_name = new PayerName(
|
||||
isset( $data->name->given_name ) ? (string) $data->name->given_name : '',
|
||||
isset( $data->name->surname ) ? (string) $data->name->surname : ''
|
||||
|
|
|
@ -153,8 +153,8 @@ class PurchaseUnitFactory {
|
|||
if ( $this->shipping_needed( ... array_values( $items ) ) && is_a( $customer, \WC_Customer::class ) ) {
|
||||
$shipping = $this->shipping_factory->from_wc_customer( \WC()->customer );
|
||||
if (
|
||||
! $shipping->address()->country_code()
|
||||
|| ( $shipping->address()->country_code() && ! $shipping->address()->postal_code() )
|
||||
2 !== strlen( $shipping->address()->country_code() )
|
||||
|| ( ! $shipping->address()->postal_code() )
|
||||
) {
|
||||
$shipping = null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue