mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Add suspend subscription to my account
This commit is contained in:
parent
610ba3e935
commit
74d1b03463
2 changed files with 54 additions and 1 deletions
|
@ -281,6 +281,27 @@ class SubscriptionModule implements ModuleInterface {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
add_action('woocommerce_subscription_before_actions', function($subscription) {
|
||||||
|
$subscription_id = $subscription->get_meta( 'ppcp_subscription' ) ?? '';
|
||||||
|
if ( $subscription_id) { ?>
|
||||||
|
<tr>
|
||||||
|
<td><?php esc_html_e( 'PayPal Subscription', 'woocommerce-paypal-payments' ); ?></td>
|
||||||
|
<td>
|
||||||
|
<a href="<?php echo esc_url( "https://www.sandbox.paypal.com/myaccount/autopay/connect/{$subscription_id}" ); ?>" id="ppcp-subscription-id" target="_blank"><?php echo esc_html( $subscription_id ); ?></a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php }
|
||||||
|
});
|
||||||
|
|
||||||
|
add_filter( 'wcs_view_subscription_actions', function($actions, $subscription) {
|
||||||
|
$subscription_id = $subscription->get_meta( 'ppcp_subscription' ) ?? '';
|
||||||
|
if ( $subscription_id && $subscription->get_status() === 'active') {
|
||||||
|
$actions['cancel']['name'] = esc_html__('Suspend', 'woocommerce-paypal-payments');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $actions;
|
||||||
|
}, 10, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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}) => {
|
test('Purchase Subscription from Checkout Page', async ({page}) => {
|
||||||
await loginAsCustomer(page);
|
await loginAsCustomer(page);
|
||||||
|
|
||||||
|
@ -186,4 +186,36 @@ test.describe('Subscriptions Customer', () => {
|
||||||
const title = page.locator('.entry-title');
|
const title = page.locator('.entry-title');
|
||||||
await expect(title).toHaveText('Order received');
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue