Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 89cca00

Browse files
committed
Add discount functionality to app billing functions
1 parent f235f7e commit 89cca00

5 files changed

Lines changed: 37 additions & 3 deletions

File tree

.changeset/long-brooms-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/shopify-api': minor
3+
---
4+
5+
Discount functionality for App Billing Fixes #731

docs/guides/billing.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The Admin API provides endpoints that enable apps to trigger purchases in the Sh
55

66
See the [billing reference](../reference/billing/README.md) for details on how to call those endpoints, using this configuration.
77

8-
To trigger the billing behaviour, you'll need to set the `billing` value when calling `shopifyApi()`. For example:
8+
To trigger the billing behaviour, you'll need to set the `billing` value when calling `shopifyApi()`. For example the following configuration will allow you to charge merchants $30 every 30 days. The first three charges will be discounted by $10, so merchants would be charged $20.
99

1010
```ts
1111
import {
@@ -19,9 +19,15 @@ const shopify = shopifyApi({
1919
billing: {
2020
'My billing plan': {
2121
interval: BillingInterval.Every30Days,
22-
amount: 1,
22+
amount: 30,
2323
currencyCode: 'USD',
2424
replacementBehavior: BillingReplacementBehavior.ApplyImmediately,
25+
discount: {
26+
durationLimitInIntervals: 3,
27+
value: {
28+
amount: 10,
29+
},
30+
}
2531
},
2632
},
2733
});
@@ -35,7 +41,7 @@ This setting is a collection of billing plans. Each billing plan allows the foll
3541
| -------------- | ---------- | :-------: | :-----------: | ---------------------------------------------------------- |
3642
| `interval` | `ONE_TIME` | Yes | - | `BillingInterval.OneTime` value |
3743
| `amount` | `number` | Yes | - | The amount to charge |
38-
| `currencyCode` | `string` | Yes | - | The currency to charge, currently only `"USD"` is accepted |
44+
| `currencyCode` | `string` | Yes | - | The currency to charge, USD or merchant's shop currency |
3945

4046
### Recurring Billing Plans
4147

@@ -46,6 +52,9 @@ This setting is a collection of billing plans. Each billing plan allows the foll
4652
| `currencyCode` | `string` | Yes | - | The currency to charge, currently only `"USD"` is accepted |
4753
| `trialDays` | `number` | No | - | Give merchants this many days before charging |
4854
| `replacementBehavior` | `BillingReplacementBehavior` | No | - | `BillingReplacementBehavior` value, see [the reference](https://shopify.dev/docs/api/admin-graphql/latest/mutations/appSubscriptionCreate) for more information. |
55+
| `discount.durationLimitInIntervals` | `number` | No | - | The number of billing intervals to apply the discount for. See the [reference](https://shopify.dev/docs/apps/billing/purchase-adjustments/subscription-discounts) for more information |
56+
| `discount.value.amount` | `number` | No | - | The amount of the discount in the currency that the merchant is being billed in. |
57+
| `discount.value.percentage` | `number` | No | - | The percentage value of the discount. |
4958

5059
### Usage Billing Plans
5160

lib/billing/__tests__/request_payment.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ describe('shopify.billing.request', () => {
230230
currencyCode: 'USD',
231231
interval: BillingInterval.Every30Days,
232232
replacementBehavior: BillingReplacementBehavior.ApplyImmediately,
233+
discount: {
234+
value: {
235+
amount: 1,
236+
},
237+
},
233238
trialDays: 10,
234239
},
235240
},

lib/billing/request.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ async function requestRecurringPayment({
131131
amount: billingConfig.amount,
132132
currencyCode: billingConfig.currencyCode,
133133
},
134+
discount: {
135+
durationLimitInIntervals:
136+
billingConfig.discount?.durationLimitInIntervals,
137+
value: {
138+
amount: billingConfig.discount?.value?.amount,
139+
percentage: billingConfig.discount?.value?.percentage,
140+
},
141+
},
134142
},
135143
},
136144
},

lib/billing/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ export interface BillingConfigSubscriptionPlan extends BillingConfigPlan {
1818
interval: RecurringBillingIntervals;
1919
trialDays?: number;
2020
replacementBehavior?: BillingReplacementBehavior;
21+
discount?: {
22+
durationLimitInIntervals?: number;
23+
value: {
24+
amount?: number;
25+
percentage?: number;
26+
};
27+
};
2128
}
2229

2330
export interface BillingConfigUsagePlan extends BillingConfigPlan {

0 commit comments

Comments
 (0)