Skip to content

Commit bd1c712

Browse files
committed
feat(foxy-admin-subscription-form): add Charge Past Due button
1 parent f4a55ad commit bd1c712

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed

src/elements/public/AdminSubscriptionForm/AdminSubscriptionForm.test.ts

+33
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ describe('AdminSubscriptionForm', () => {
1616
before(() => (window.ResizeObserver = undefined));
1717
after(() => (window.ResizeObserver = OriginalResizeObserver));
1818

19+
it('imports and defines foxy-internal-post-action-control', () => {
20+
expect(customElements.get('foxy-internal-post-action-control')).to.exist;
21+
});
22+
1923
it('imports and defines foxy-internal-async-list-control', () => {
2024
expect(customElements.get('foxy-internal-async-list-control')).to.exist;
2125
});
@@ -238,6 +242,35 @@ describe('AdminSubscriptionForm', () => {
238242
expect(control?.localName).to.equal('foxy-internal-summary-control');
239243
});
240244

245+
it('renders post action control for charging past due amount when appropriate', async () => {
246+
const router = createRouter();
247+
const form = await fixture<Form>(html`
248+
<foxy-admin-subscription-form
249+
href="https://demo.api/hapi/subscriptions/0?zoom=transaction_template"
250+
@fetch=${(evt: FetchEvent) => router.handleEvent(evt)}
251+
>
252+
</foxy-admin-subscription-form>
253+
`);
254+
255+
const testData = await getTestData<Data>('./hapi/subscriptions/0?zoom=transaction_template');
256+
// @ts-expect-error - SDK doesn't know yet about the `fx:charge_past_due` link.
257+
testData._links['fx:charge_past_due'] = { href: 'https://demo.api/virtual/empty' };
258+
testData.past_due_amount = 10;
259+
testData._embedded['fx:transaction_template'].currency_code = 'AUD';
260+
form.data = testData;
261+
262+
await waitUntil(() => !!form.data, '', { timeout: 5000 });
263+
await form.requestUpdate();
264+
const summary = form.renderRoot.querySelector('[infer="overdue"]');
265+
const control = summary?.querySelector('[infer="charge-past-due"]');
266+
267+
expect(control?.localName).to.equal('foxy-internal-post-action-control');
268+
expect(control).to.have.attribute('theme', 'tertiary-inline');
269+
expect(control).to.have.attribute('message-options', JSON.stringify({ amount: '10 AUD' }));
270+
expect(control).to.have.attribute('href', 'https://demo.api/virtual/empty');
271+
expect(control).to.have.attribute('href', 'https://demo.api/virtual/empty');
272+
});
273+
241274
it('renders number control for past due amount inside of the overdue summary control', async () => {
242275
const router = createRouter();
243276
const form = await fixture<Form>(html`

src/elements/public/AdminSubscriptionForm/AdminSubscriptionForm.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export class AdminSubscriptionForm extends Base<Data> {
4646
transactionsHref = undefined;
4747
}
4848

49+
// @ts-expect-error - SDK doesn't know yet about the `fx:charge_past_due` link.
50+
const chargePastDueHref: string | undefined = this.data?._links['fx:charge_past_due']?.href;
51+
const pastDueAmount = this.data?.past_due_amount;
52+
const currencyCode = this.data?._embedded['fx:transaction_template'].currency_code;
53+
4954
return html`
5055
${this.renderHeader()}
5156
@@ -70,11 +75,24 @@ export class AdminSubscriptionForm extends Base<Data> {
7075
<foxy-internal-summary-control infer="overdue">
7176
<foxy-internal-number-control
7277
layout="summary-item"
73-
suffix=${ifDefined(this.data?._embedded['fx:transaction_template'].currency_code)}
78+
suffix=${ifDefined(currencyCode)}
7479
infer="past-due-amount"
7580
min="0"
7681
>
7782
</foxy-internal-number-control>
83+
84+
${chargePastDueHref && currencyCode && pastDueAmount
85+
? html`
86+
<foxy-internal-post-action-control
87+
message-options=${JSON.stringify({ amount: `${pastDueAmount} ${currencyCode}` })}
88+
theme="tertiary-inline"
89+
infer="charge-past-due"
90+
href=${chargePastDueHref}
91+
@success=${() => this.refresh()}
92+
>
93+
</foxy-internal-post-action-control>
94+
`
95+
: ''}
7896
</foxy-internal-summary-control>
7997
8098
<foxy-internal-summary-control infer="self-service-links">

src/elements/public/AdminSubscriptionForm/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import '../../internal/InternalPostActionControl/index';
12
import '../../internal/InternalAsyncListControl/index';
23
import '../../internal/InternalFrequencyControl/index';
34
import '../../internal/InternalNumberControl/index';

src/static/translations/admin-subscription-form/en.json

+16
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@
9393
"helper_text": "Missing payments increase this amount. Depending on your store settings, we may charge it automatically on the next billing cycle.",
9494
"placeholder": "0",
9595
"clear": "Clear"
96+
},
97+
"charge-past-due": {
98+
"button": {
99+
"idle": "Charge past due amount",
100+
"busy": "Processing..."
101+
},
102+
"notification": {
103+
"success": "Past due amount successfully charged.",
104+
"error": "Failed to charge past due amount."
105+
},
106+
"confirm-dialog": {
107+
"message": "This will attempt to charge the past due amount of {{ amount, price }}. Would you like to proceed?",
108+
"confirm": "Yes",
109+
"cancel": "No",
110+
"header": "Past due payment"
111+
}
96112
}
97113
},
98114
"self-service-links": {

0 commit comments

Comments
 (0)