diff --git a/modules/ppcp-subscription/src/SubscriptionModule.php b/modules/ppcp-subscription/src/SubscriptionModule.php
index 345afc754..193788460 100644
--- a/modules/ppcp-subscription/src/SubscriptionModule.php
+++ b/modules/ppcp-subscription/src/SubscriptionModule.php
@@ -281,6 +281,27 @@ class SubscriptionModule implements ModuleInterface {
return;
}
} );
+
+ add_action('woocommerce_subscription_before_actions', function($subscription) {
+ $subscription_id = $subscription->get_meta( 'ppcp_subscription' ) ?? '';
+ if ( $subscription_id) { ?>
+
+ |
+
+ " id="ppcp-subscription-id" target="_blank">
+ |
+
+ get_meta( 'ppcp_subscription' ) ?? '';
+ if ( $subscription_id && $subscription->get_status() === 'active') {
+ $actions['cancel']['name'] = esc_html__('Suspend', 'woocommerce-paypal-payments');
+ }
+
+ return $actions;
+ }, 10, 2);
}
/**
diff --git a/tests/playwright/subscriptions-api.spec.js b/tests/playwright/subscriptions-api.spec.js
index 1e5d87da3..bce3b62fa 100644
--- a/tests/playwright/subscriptions-api.spec.js
+++ b/tests/playwright/subscriptions-api.spec.js
@@ -107,7 +107,7 @@ test.describe.serial('Subscriptions Merchant', () => {
});
});
-test.describe('Subscriptions Customer', () => {
+test.describe('Subscriber purchase a Subscription', () => {
test('Purchase Subscription from Checkout Page', async ({page}) => {
await loginAsCustomer(page);
@@ -186,4 +186,36 @@ test.describe('Subscriptions Customer', () => {
const title = page.locator('.entry-title');
await expect(title).toHaveText('Order received');
});
+
+ test('Subscriber Suspend Subscription', async ({page, request}) => {
+ await loginAsCustomer(page);
+ await page.goto('/my-account/subscriptions');
+ await page.locator('text=View').first().click();
+
+ const subscriptionId = await page.locator('#ppcp-subscription-id').textContent();
+ let subscription = await request.get(`https://api.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, {
+ headers: {
+ 'Authorization': AUTHORIZATION,
+ 'Content-Type': 'application/json'
+ }
+ });
+ expect(subscription.ok()).toBeTruthy();
+ let details = await subscription.json();
+ await expect(details.status).toBe('ACTIVE');
+
+ await page.locator('text=Suspend').click();
+ const title = page.locator('.woocommerce-message');
+ await expect(title).toHaveText('Your subscription has been cancelled.');
+
+ subscription = await request.get(`https://api.sandbox.paypal.com/v1/billing/subscriptions/${subscriptionId}`, {
+ headers: {
+ 'Authorization': AUTHORIZATION,
+ 'Content-Type': 'application/json'
+ }
+ });
+ expect(subscription.ok()).toBeTruthy();
+
+ details = await subscription.json();
+ await expect(details.status).toBe('SUSPENDED');
+ });
});