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

Commit

Permalink
Applying comments from review
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Sep 5, 2023
1 parent 5da6add commit 05c395a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .changeset/tasty-foxes-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'@shopify/shopify-api': minor
---

Add new trialDaysOverride parameter to billing.request, so that apps can override the default config value.
Add new trialDays parameter to billing.request, so that apps can override the default config value.
2 changes: 1 addition & 1 deletion docs/reference/billing/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Which URL to redirect the merchant to after the charge is confirmed.

Whether to return the `confirmationUrl` as a `string`, or to return a more detailed object (see below).

### trialDaysOverride
### trialDays

`number`

Expand Down
4 changes: 2 additions & 2 deletions lib/billing/__tests__/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ describe('shopify.billing.request', () => {
session,
plan: Responses.PLAN_1,
returnObject: true,
trialDaysOverride: 20,
trialDays: 20,
});

expect({
Expand Down Expand Up @@ -462,7 +462,7 @@ describe('shopify.billing.request', () => {
session,
plan: Responses.PLAN_1,
returnObject: true,
trialDaysOverride: 0,
trialDays: 0,
});

expect({
Expand Down
30 changes: 13 additions & 17 deletions lib/billing/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface RequestInternalParams {

interface RequestSubscriptionInternalParams extends RequestInternalParams {
billingConfig: BillingConfigSubscriptionPlan;
trialDaysOverride?: number;
trialDays?: number;
}

interface RequestOneTimePaymentInternalParams extends RequestInternalParams {
Expand All @@ -38,7 +38,7 @@ interface RequestOneTimePaymentInternalParams extends RequestInternalParams {

interface RequestUsageSubscriptionInternalParams extends RequestInternalParams {
billingConfig: BillingConfigUsagePlan;
trialDaysOverride?: number;
trialDays?: number;
}

export function request(config: ConfigInterface) {
Expand All @@ -48,7 +48,7 @@ export function request(config: ConfigInterface) {
isTest = true,
returnUrl: returnUrlParam,
returnObject = false,
trialDaysOverride = undefined,
trialDays = undefined,
}: Params): Promise<BillingRequestResponse<Params>> {
if (!config.billing || !config.billing[plan]) {
throw new BillingError({
Expand Down Expand Up @@ -93,7 +93,7 @@ export function request(config: ConfigInterface) {
client,
returnUrl,
isTest,
trialDaysOverride,
trialDays,
});
data = mutationUsageResponse.data.appSubscriptionCreate;
break;
Expand All @@ -105,7 +105,7 @@ export function request(config: ConfigInterface) {
client,
returnUrl,
isTest,
trialDaysOverride,
trialDays,
});
data = mutationRecurringResponse.data.appSubscriptionCreate;
}
Expand Down Expand Up @@ -134,18 +134,16 @@ async function requestRecurringPayment({
client,
returnUrl,
isTest,
trialDaysOverride,
trialDays,
}: RequestSubscriptionInternalParams): Promise<RecurringPaymentResponse> {
const trialDays =
trialDaysOverride === undefined
? billingConfig.trialDays
: trialDaysOverride;
const trialDaysValue =
trialDays === undefined ? billingConfig.trialDays : trialDays;
const mutationResponse = await client.query<RecurringPaymentResponse>({
data: {
query: RECURRING_PURCHASE_MUTATION,
variables: {
name: plan,
trialDays,
trialDays: trialDaysValue,
replacementBehavior: billingConfig.replacementBehavior,
returnUrl,
test: isTest,
Expand Down Expand Up @@ -190,20 +188,18 @@ async function requestUsagePayment({
client,
returnUrl,
isTest,
trialDaysOverride,
trialDays,
}: RequestUsageSubscriptionInternalParams): Promise<RecurringPaymentResponse> {
const trialDays =
trialDaysOverride === undefined
? billingConfig.trialDays
: trialDaysOverride;
const trialDaysValue =
trialDays === undefined ? billingConfig.trialDays : trialDays;
const mutationResponse = await client.query<RecurringPaymentResponse>({
data: {
query: RECURRING_PURCHASE_MUTATION,
variables: {
name: plan,
returnUrl,
test: isTest,
trialDays,
trialDays: trialDaysValue,
replacementBehavior: billingConfig.replacementBehavior,
lineItems: [
{
Expand Down
2 changes: 1 addition & 1 deletion lib/billing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export interface BillingRequestParams {
isTest?: boolean;
returnUrl?: string;
returnObject?: boolean;
trialDaysOverride?: number;
trialDays?: number;
}

export interface BillingRequestResponseObject {
Expand Down

0 comments on commit 05c395a

Please sign in to comment.