mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 13:44:42 +08:00
Merge branch 'task/shared-apple-google' into PCP-1744-google-pay-integration
# Conflicts: # modules/ppcp-button/src/Assets/SmartButton.php # modules/ppcp-onboarding/src/Render/OnboardingOptionsRenderer.php
This commit is contained in:
commit
e39e29aece
6 changed files with 37 additions and 5 deletions
|
@ -1171,7 +1171,7 @@ class SmartButton implements SmartButtonInterface {
|
||||||
/**
|
/**
|
||||||
* Filter to add further components from the extensions.
|
* Filter to add further components from the extensions.
|
||||||
*
|
*
|
||||||
* @internal Matches filter name in GooglePay extension.
|
* @internal Matches filter name in APM extension.
|
||||||
* @since TODO
|
* @since TODO
|
||||||
*
|
*
|
||||||
* @param array $components The array of components already registered.
|
* @param array $components The array of components already registered.
|
||||||
|
|
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace WooCommerce\PayPalCommerce\Subscription;
|
namespace WooCommerce\PayPalCommerce\Subscription;
|
||||||
|
|
||||||
|
use WC_Subscription;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||||
|
@ -139,8 +140,16 @@ class RenewalHandler {
|
||||||
*
|
*
|
||||||
* @param \WC_Order $wc_order The WooCommerce order.
|
* @param \WC_Order $wc_order The WooCommerce order.
|
||||||
*/
|
*/
|
||||||
public function renew( \WC_Order $wc_order ) {
|
public function renew( \WC_Order $wc_order ): void {
|
||||||
try {
|
try {
|
||||||
|
$subscription = wcs_get_subscription( $wc_order->get_id() );
|
||||||
|
if ( is_a( $subscription, WC_Subscription::class ) ) {
|
||||||
|
$subscription_id = $subscription->get_meta( 'ppcp_subscription' ) ?? '';
|
||||||
|
if ( $subscription_id ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->process_order( $wc_order );
|
$this->process_order( $wc_order );
|
||||||
} catch ( \Exception $exception ) {
|
} catch ( \Exception $exception ) {
|
||||||
$error = $exception->getMessage();
|
$error = $exception->getMessage();
|
||||||
|
|
|
@ -74,6 +74,11 @@ class SubscriptionModule implements ModuleInterface {
|
||||||
add_action(
|
add_action(
|
||||||
'woocommerce_subscription_payment_complete',
|
'woocommerce_subscription_payment_complete',
|
||||||
function ( $subscription ) use ( $c ) {
|
function ( $subscription ) use ( $c ) {
|
||||||
|
$paypal_subscription_id = $subscription->get_meta( 'ppcp_subscription' ) ?? '';
|
||||||
|
if ( $paypal_subscription_id ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$payment_token_repository = $c->get( 'vaulting.repository.payment-token' );
|
$payment_token_repository = $c->get( 'vaulting.repository.payment-token' );
|
||||||
$logger = $c->get( 'woocommerce.logger.woocommerce' );
|
$logger = $c->get( 'woocommerce.logger.woocommerce' );
|
||||||
|
|
||||||
|
|
|
@ -92,10 +92,24 @@ class PaymentSaleCompleted implements RequestHandler {
|
||||||
);
|
);
|
||||||
$subscriptions = wcs_get_subscriptions( $args );
|
$subscriptions = wcs_get_subscriptions( $args );
|
||||||
foreach ( $subscriptions as $subscription ) {
|
foreach ( $subscriptions as $subscription ) {
|
||||||
$parent_order = wc_get_order( $subscription->get_parent() );
|
|
||||||
$transaction_id = wc_clean( wp_unslash( $request['resource']['id'] ?? '' ) );
|
$transaction_id = wc_clean( wp_unslash( $request['resource']['id'] ?? '' ) );
|
||||||
if ( $transaction_id && is_string( $transaction_id ) && is_a( $parent_order, WC_Order::class ) ) {
|
if ( $transaction_id && is_string( $transaction_id ) ) {
|
||||||
$this->update_transaction_id( $transaction_id, $parent_order, $this->logger );
|
$is_renewal = $subscription->get_meta( '_ppcp_is_subscription_renewal' ) ?? '';
|
||||||
|
if ( $is_renewal ) {
|
||||||
|
$renewal_order = wcs_create_renewal_order( $subscription );
|
||||||
|
if ( is_a( $renewal_order, WC_Order::class ) ) {
|
||||||
|
$renewal_order->payment_complete();
|
||||||
|
$this->update_transaction_id( $transaction_id, $renewal_order, $this->logger );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$parent_order = wc_get_order( $subscription->get_parent() );
|
||||||
|
if ( is_a( $parent_order, WC_Order::class ) ) {
|
||||||
|
$subscription->update_meta_data( '_ppcp_is_subscription_renewal', 'true' );
|
||||||
|
$subscription->save_meta_data();
|
||||||
|
$this->update_transaction_id( $transaction_id, $parent_order, $this->logger );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -115,6 +115,9 @@ class RenewalHandlerTest extends TestCase
|
||||||
->shouldReceive('payment_source')
|
->shouldReceive('payment_source')
|
||||||
->andReturn(null);
|
->andReturn(null);
|
||||||
|
|
||||||
|
$wcOrder
|
||||||
|
->shouldReceive('get_meta')
|
||||||
|
->andReturn('');
|
||||||
$wcOrder
|
$wcOrder
|
||||||
->shouldReceive('get_id')
|
->shouldReceive('get_id')
|
||||||
->andReturn(1);
|
->andReturn(1);
|
||||||
|
|
|
@ -38,6 +38,7 @@ class TestCase extends \PHPUnit\Framework\TestCase
|
||||||
when('wc_clean')->returnArg();
|
when('wc_clean')->returnArg();
|
||||||
when('get_transient')->returnArg();
|
when('get_transient')->returnArg();
|
||||||
when('delete_transient')->returnArg();
|
when('delete_transient')->returnArg();
|
||||||
|
when('wcs_get_subscription')->returnArg();
|
||||||
|
|
||||||
setUp();
|
setUp();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue