Merge branch 'trunk' into pcp-401-custom-order-id

This commit is contained in:
Alex P 2021-11-23 12:51:26 +02:00
commit 6e6b4c4b40
18 changed files with 201 additions and 205 deletions

View file

@ -130,14 +130,15 @@ return array(
);
},
'api.endpoint.identity-token' => static function ( ContainerInterface $container ) : IdentityToken {
$logger = $container->get( 'woocommerce.logger.woocommerce' );
$prefix = $container->get( 'api.prefix' );
$settings = $container->get( 'wcgateway.settings' );
return new IdentityToken(
$container->get( 'api.host' ),
$container->get( 'api.bearer' ),
$logger,
$prefix
$prefix,
$settings
);
},
'api.endpoint.payments' => static function ( ContainerInterface $container ): PaymentsEndpoint {

View file

@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Entity\Token;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
/**
* Class IdentityToken
@ -50,6 +51,13 @@ class IdentityToken {
*/
private $prefix;
/**
* The settings
*
* @var Settings
*/
private $settings;
/**
* IdentityToken constructor.
*
@ -57,12 +65,14 @@ class IdentityToken {
* @param Bearer $bearer The bearer.
* @param LoggerInterface $logger The logger.
* @param string $prefix The prefix.
* @param Settings $settings The settings.
*/
public function __construct( string $host, Bearer $bearer, LoggerInterface $logger, string $prefix ) {
$this->host = $host;
$this->bearer = $bearer;
$this->logger = $logger;
$this->prefix = $prefix;
public function __construct( string $host, Bearer $bearer, LoggerInterface $logger, string $prefix, Settings $settings ) {
$this->host = $host;
$this->bearer = $bearer;
$this->logger = $logger;
$this->prefix = $prefix;
$this->settings = $settings;
}
/**
@ -84,7 +94,11 @@ class IdentityToken {
'Content-Type' => 'application/json',
),
);
if ( $customer_id && defined( 'PPCP_FLAG_SUBSCRIPTION' ) && PPCP_FLAG_SUBSCRIPTION ) {
if (
$customer_id
&& ( $this->settings->has( 'vault_enabled' ) && $this->settings->get( 'vault_enabled' ) )
&& defined( 'PPCP_FLAG_SUBSCRIPTION' ) && PPCP_FLAG_SUBSCRIPTION
) {
$args['body'] = wp_json_encode( array( 'customer_id' => $this->prefix . $customer_id ) );
}

View file

@ -121,8 +121,10 @@ class PurchaseUnitFactory {
$payee = $this->payee_repository->payee();
$custom_id = (string) $order->get_id();
$invoice_id = $this->prefix . $order->get_order_number();
$retry = $order->get_meta( 'ppcp-retry' ) ? '-' . $order->get_meta( 'ppcp-retry' ) : '';
$soft_descriptor = '';
$purchase_unit = new PurchaseUnit(
$purchase_unit = new PurchaseUnit(
$amount,
$items,
$shipping,