Merge pull request #1964 from woocommerce/PCP-2558-advanced-wallet-reference-transactions-signup-link-from-connection-tab

Add setup URL for reference transactions.
This commit is contained in:
Emili Castells 2024-01-23 15:49:09 +01:00 committed by GitHub
commit b4010e2472
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 58 additions and 2 deletions

View file

@ -71,7 +71,7 @@ return array(
// Connection tab fields.
$fields = $insert_after(
$fields,
'ppcp_dcc_status',
'ppcp_reference_transactions_status',
array(
'applepay_status' => array(
'title' => __( 'Apple Pay Payments', 'woocommerce-paypal-payments' ),

View file

@ -42,7 +42,7 @@ return array(
// Connection tab fields.
$fields = $insert_after(
$fields,
'ppcp_dcc_status',
'ppcp_reference_transactions_status',
array(
'googlepay_status' => array(
'title' => __( 'Google Pay Payments', 'woocommerce-paypal-payments' ),

View file

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\PayUponInvoiceOrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\ApplicationContext;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
@ -1315,6 +1316,12 @@ return array(
'wcgateway.enable-pui-url-live' => static function ( ContainerInterface $container ): string {
return 'https://www.paypal.com/bizsignup/entry?country.x=DE&product=payment_methods&capabilities=PAY_UPON_INVOICE';
},
'wcgateway.enable-reference-transactions-url-sandbox' => static function ( ContainerInterface $container ): string {
return 'https://www.sandbox.paypal.com/bizsignup/entry?product=ADVANCED_VAULTING';
},
'wcgateway.enable-reference-transactions-url-live' => static function ( ContainerInterface $container ): string {
return 'https://www.paypal.com/bizsignup/entry?product=ADVANCED_VAULTING';
},
'wcgateway.settings.connection.dcc-status-text' => static function ( ContainerInterface $container ): string {
$state = $container->get( 'onboarding.state' );
if ( $state->current_state() < State::STATE_ONBOARDED ) {
@ -1353,6 +1360,39 @@ return array(
esc_html( $dcc_button_text )
);
},
'wcgateway.settings.connection.reference-transactions-status-text' => static function ( ContainerInterface $container ): string {
$environment = $container->get( 'onboarding.environment' );
assert( $environment instanceof Environment );
$billing_agreements_endpoint = $container->get( 'api.endpoint.billing-agreements' );
assert( $billing_agreements_endpoint instanceof BillingAgreementsEndpoint );
$enabled = $billing_agreements_endpoint->reference_transaction_enabled();
$enabled_status_text = esc_html__( 'Status: Available', 'woocommerce-paypal-payments' );
$disabled_status_text = esc_html__( 'Status: Not yet enabled', 'woocommerce-paypal-payments' );
$button_text = $enabled
? esc_html__( 'Settings', 'woocommerce-paypal-payments' )
: esc_html__( 'Enable Advanced PayPal Wallet', 'woocommerce-paypal-payments' );
$enable_url = $environment->current_environment_is( Environment::PRODUCTION )
? $container->get( 'wcgateway.enable-reference-transactions-url-live' )
: $container->get( 'wcgateway.enable-reference-transactions-url-sandbox' );
$button_url = $enabled
? admin_url( 'admin.php?page=wc-settings&tab=checkout&section=ppcp-gateway#field-paypal_saved_payments' )
: $enable_url;
return sprintf(
'<p>%1$s %2$s</p><p><a target="%3$s" href="%4$s" class="button">%5$s</a></p>',
$enabled ? $enabled_status_text : $disabled_status_text,
$enabled ? '<span class="dashicons dashicons-yes"></span>' : '<span class="dashicons dashicons-no"></span>',
$enabled ? '_self' : '_blank',
esc_url( $button_url ),
esc_html( $button_text )
);
},
'wcgateway.settings.connection.pui-status-text' => static function ( ContainerInterface $container ): string {
$state = $container->get( 'onboarding.state' );
if ( $state->current_state() < State::STATE_ONBOARDED ) {

View file

@ -410,6 +410,16 @@ return function ( ContainerInterface $container, array $fields ): array {
'requirements' => array( 'dcc' ),
'gateway' => Settings::CONNECTION_TAB_ID,
),
'ppcp_reference_transactions_status' => array(
'title' => __( 'Advanced PayPal Wallet', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text',
'text' => $container->get( 'wcgateway.settings.connection.reference-transactions-status-text' ),
'screens' => array(
State::STATE_ONBOARDED,
),
'requirements' => array( 'dcc' ),
'gateway' => Settings::CONNECTION_TAB_ID,
),
'ppcp_pui_status' => array(
'title' => __( 'Pay upon Invoice', 'woocommerce-paypal-payments' ),
'type' => 'ppcp-text',

View file

@ -435,15 +435,21 @@ class WCGatewayModule implements ModuleInterface {
add_action(
'woocommerce_paypal_payments_clear_apm_product_status',
function( Settings $settings = null ) use ( $c ): void {
// Clear DCC Product status.
$dcc_product_status = $c->get( 'wcgateway.helper.dcc-product-status' );
if ( $dcc_product_status instanceof DCCProductStatus ) {
$dcc_product_status->clear( $settings );
}
// Clear Pay Upon Invoice status.
$pui_product_status = $c->get( 'wcgateway.pay-upon-invoice-product-status' );
if ( $pui_product_status instanceof PayUponInvoiceProductStatus ) {
$pui_product_status->clear( $settings );
}
// Clear Reference Transaction status.
delete_transient( 'ppcp_reference_transaction_enabled' );
}
);
}