Merge branch 'trunk' into PCP-726-add-oxxo-apm-alternative-payment

This commit is contained in:
Alex P 2022-07-26 16:59:27 +03:00
commit 1049fda586
49 changed files with 1586 additions and 668 deletions

View file

@ -400,6 +400,60 @@ return array(
);
},
'api.shop.is-latin-america' => static function ( ContainerInterface $container ): bool {
return in_array(
$container->get( 'api.shop.country' ),
array(
'AI',
'AG',
'AR',
'AW',
'BS',
'BB',
'BZ',
'BM',
'BO',
'BR',
'VG',
'KY',
'CL',
'CO',
'CR',
'DM',
'DO',
'EC',
'SV',
'FK',
'GF',
'GD',
'GP',
'GT',
'GY',
'HN',
'JM',
'MQ',
'MX',
'MS',
'AN',
'NI',
'PA',
'PY',
'PE',
'KN',
'LC',
'PM',
'VC',
'SR',
'TT',
'TC',
'UY',
'VE',
),
true
);
},
/**
* Currencies supported by PayPal.
*

View file

@ -106,7 +106,7 @@ class IdentityToken {
&& defined( 'PPCP_FLAG_SUBSCRIPTION' ) && PPCP_FLAG_SUBSCRIPTION
) {
$customer_id = $this->customer_repository->customer_id_for_user( ( $user_id ) );
update_user_meta( $user_id, 'ppcp_customer_id', $customer_id );
$args['body'] = wp_json_encode(
array(
'customer_id' => $customer_id,

View file

@ -194,7 +194,7 @@ class OrderEndpoint {
'application_context' => $this->application_context_repository
->current_context( $shipping_preference )->to_array(),
);
if ( $payer && ! empty( $payer->email_address() ) && ! empty( $payer->name() ) ) {
if ( $payer && ! empty( $payer->email_address() ) ) {
$data['payer'] = $payer->to_array();
}
if ( $payment_token ) {

View file

@ -18,7 +18,7 @@ class Payer {
/**
* The name.
*
* @var PayerName
* @var PayerName|null
*/
private $name;
@ -46,7 +46,7 @@ class Payer {
/**
* The address.
*
* @var Address
* @var Address|null
*/
private $address;
@ -67,7 +67,7 @@ class Payer {
/**
* Payer constructor.
*
* @param PayerName $name The name.
* @param PayerName|null $name The name.
* @param string $email_address The email.
* @param string $payer_id The payer id.
* @param Address|null $address The address.
@ -76,7 +76,7 @@ class Payer {
* @param PayerTaxInfo|null $tax_info The tax info.
*/
public function __construct(
PayerName $name,
?PayerName $name,
string $email_address,
string $payer_id,
Address $address = null,
@ -97,12 +97,21 @@ class Payer {
/**
* Returns the name.
*
* @return PayerName
* @return PayerName|null
*/
public function name(): PayerName {
public function name(): ?PayerName {
return $this->name;
}
/**
* Sets the name.
*
* @param PayerName|null $name The value.
*/
public function set_name( ?PayerName $name ): void {
$this->name = $name;
}
/**
* Returns the email address.
*
@ -139,6 +148,15 @@ class Payer {
return $this->address;
}
/**
* Sets the address.
*
* @param Address|null $address The value.
*/
public function set_address( ?Address $address ): void {
$this->address = $address;
}
/**
* Returns the phone.
*
@ -164,27 +182,26 @@ class Payer {
*/
public function to_array() {
$payer = array(
'name' => $this->name()->to_array(),
'email_address' => $this->email_address(),
);
if ( $this->address() ) {
$payer['address'] = $this->address->to_array();
if ( 2 !== strlen( $this->address()->country_code() ) ) {
unset( $payer['address'] );
}
if ( $this->name ) {
$payer['name'] = $this->name->to_array();
}
if ( $this->payer_id() ) {
$payer['payer_id'] = $this->payer_id();
if ( $this->address && 2 === strlen( $this->address->country_code() ) ) {
$payer['address'] = $this->address->to_array();
}
if ( $this->payer_id ) {
$payer['payer_id'] = $this->payer_id;
}
if ( $this->phone() ) {
$payer['phone'] = $this->phone()->to_array();
if ( $this->phone ) {
$payer['phone'] = $this->phone->to_array();
}
if ( $this->tax_info() ) {
$payer['tax_info'] = $this->tax_info()->to_array();
if ( $this->tax_info ) {
$payer['tax_info'] = $this->tax_info->to_array();
}
if ( $this->birthdate() ) {
$payer['birth_date'] = $this->birthdate()->format( 'Y-m-d' );
if ( $this->birthdate ) {
$payer['birth_date'] = $this->birthdate->format( 'Y-m-d' );
}
return $payer;
}

View file

@ -111,15 +111,6 @@ class PayPalApiException extends RuntimeException {
return false;
}
/**
* Returns response issues.
*
* @return array
*/
public function issues(): array {
return $this->response->issues ?? array();
}
/**
* The HTTP status code.
*

View file

@ -15,6 +15,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Item;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Money;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use WooCommerce\PayPalCommerce\Subscription\FreeTrialHandlerTrait;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
@ -132,7 +133,7 @@ class AmountFactory {
$total_value = (float) $order->get_total();
if ( (
CreditCardGateway::ID === $order->get_payment_method()
in_array( $order->get_payment_method(), array( CreditCardGateway::ID, CardButtonGateway::ID ), true )
|| ( PayPalGateway::ID === $order->get_payment_method() && 'card' === $order->get_meta( PayPalGateway::ORDER_PAYMENT_SOURCE_META_KEY ) )
)
&& $this->is_free_trial_order( $order )

View file

@ -57,6 +57,6 @@ class CustomerRepository {
return $guest_customer_id;
}
return $this->prefix . (string) $user_id;
return get_user_meta( $user_id, 'ppcp_customer_id', true ) ?: $this->prefix . (string) $user_id;
}
}