mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Merge branch 'trunk' into pcp-475-free-trial
This commit is contained in:
commit
1b5052a858
5 changed files with 48 additions and 9 deletions
|
@ -226,7 +226,7 @@ class OrderEndpoint {
|
|||
'application_context' => $this->application_context_repository
|
||||
->current_context( $shipping_preference )->to_array(),
|
||||
);
|
||||
if ( $payer ) {
|
||||
if ( $payer && ! empty( $payer->email_address() ) && ! empty( $payer->name() ) ) {
|
||||
$data['payer'] = $payer->to_array();
|
||||
}
|
||||
if ( $payment_token ) {
|
||||
|
@ -235,6 +235,11 @@ class OrderEndpoint {
|
|||
if ( $payment_method ) {
|
||||
$data['payment_method'] = $payment_method->to_array();
|
||||
}
|
||||
|
||||
/**
|
||||
* The filter can be used to modify the order creation request body data.
|
||||
*/
|
||||
$data = apply_filters( 'ppcp_create_order_request_body_data', $data );
|
||||
$url = trailingslashit( $this->host ) . 'v2/checkout/orders';
|
||||
$args = array(
|
||||
'method' => 'POST',
|
||||
|
|
|
@ -107,9 +107,11 @@ class OnboardingRenderer {
|
|||
$is_production ? 'production' : 'sandbox'
|
||||
);
|
||||
} catch ( RuntimeException $exception ) {
|
||||
esc_html_e(
|
||||
'We could not properly connect to PayPal. Please reload the page to continue',
|
||||
'woocommerce-paypal-payments'
|
||||
echo esc_html(
|
||||
__(
|
||||
'We could not properly connect to PayPal. Try reloading the page.',
|
||||
'woocommerce-paypal-payments'
|
||||
) . " {$exception->getMessage()} {$exception->getFile()}:{$exception->getLine()}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,8 +88,7 @@ return array(
|
|||
);
|
||||
},
|
||||
'woocommerce.logger.woocommerce' => function ( ContainerInterface $container ): LoggerInterface {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
if ( ! function_exists( 'wc_get_logger' ) || ! $settings->has( 'logging_enabled' ) || ! $settings->get( 'logging_enabled' ) ) {
|
||||
if ( ! function_exists( 'wc_get_logger' ) || ! $container->get( 'wcgateway.logging.is-enabled' ) ) {
|
||||
return new NullLogger();
|
||||
}
|
||||
|
||||
|
|
|
@ -2133,4 +2133,16 @@ return array(
|
|||
$container->get( 'wcgateway.settings' )
|
||||
);
|
||||
},
|
||||
|
||||
'wcgateway.logging.is-enabled' => function ( ContainerInterface $container ) : bool {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
|
||||
/**
|
||||
* Whether the logging of the plugin errors/events is enabled.
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_is_logging_enabled',
|
||||
$settings->has( 'logging_enabled' ) && $settings->get( 'logging_enabled' )
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
|||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PatchCollection;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payer;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PayerName;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Payments;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PurchaseUnit;
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Shipping;
|
||||
|
@ -945,7 +946,13 @@ class OrderEndpointTest extends TestCase
|
|||
);
|
||||
expect('is_wp_error')->with($rawResponse)->andReturn(false);
|
||||
expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(201);
|
||||
$result = $testee->create([$purchaseUnit]);
|
||||
|
||||
$payer = Mockery::mock(Payer::class);
|
||||
$payer
|
||||
->expects('email_address')
|
||||
->andReturn('');
|
||||
|
||||
$result = $testee->create([$purchaseUnit], $payer);
|
||||
$this->assertEquals($expectedOrder, $result);
|
||||
}
|
||||
|
||||
|
@ -1038,6 +1045,9 @@ class OrderEndpointTest extends TestCase
|
|||
expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(201);
|
||||
|
||||
$payer = Mockery::mock(Payer::class);
|
||||
$payer->expects('email_address')->andReturn('email@email.com');
|
||||
$payerName = Mockery::mock(PayerName::class);
|
||||
$payer->expects('name')->andReturn($payerName);
|
||||
$payer->expects('to_array')->andReturn(['payer']);
|
||||
$result = $testee->create([$purchaseUnit], $payer);
|
||||
$this->assertEquals($expectedOrder, $result);
|
||||
|
@ -1125,7 +1135,13 @@ class OrderEndpointTest extends TestCase
|
|||
);
|
||||
expect('is_wp_error')->with($rawResponse)->andReturn(true);
|
||||
$this->expectException(RuntimeException::class);
|
||||
$testee->create([$purchaseUnit]);
|
||||
|
||||
$payer = Mockery::mock(Payer::class);
|
||||
$payer->expects('email_address')->andReturn('email@email.com');
|
||||
$payerName = Mockery::mock(PayerName::class);
|
||||
$payer->expects('name')->andReturn($payerName);
|
||||
$payer->expects('to_array')->andReturn(['payer']);
|
||||
$testee->create([$purchaseUnit], $payer);
|
||||
}
|
||||
|
||||
public function testCreateForPurchaseUnitsIsNot201()
|
||||
|
@ -1211,6 +1227,11 @@ class OrderEndpointTest extends TestCase
|
|||
expect('is_wp_error')->with($rawResponse)->andReturn(false);
|
||||
expect('wp_remote_retrieve_response_code')->with($rawResponse)->andReturn(500);
|
||||
$this->expectException(RuntimeException::class);
|
||||
$testee->create([$purchaseUnit]);
|
||||
$payer = Mockery::mock(Payer::class);
|
||||
$payer->expects('email_address')->andReturn('email@email.com');
|
||||
$payerName = Mockery::mock(PayerName::class);
|
||||
$payer->expects('name')->andReturn($payerName);
|
||||
$payer->expects('to_array')->andReturn(['payer']);
|
||||
$testee->create([$purchaseUnit], $payer);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue