Skip to content

Commit

Permalink
feat: add union types
Browse files Browse the repository at this point in the history
  • Loading branch information
altaywtf committed Jan 17, 2024
1 parent a1a5d56 commit d639035
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/resources/Payment/Payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class Payment {

public ChangePlan(params: IChangePlanRequestParams) {
return {
get: () => {
GET: () => {
return this.client.get<IChangePlanGetResponse>(
`/payment/change_plan/${params.plan_path}`,
{
Expand All @@ -55,7 +55,7 @@ export default class Payment {
)
},

post: () => {
POST: () => {
return this.client.post<IChangePlanPostResponse>(
`/payment/change_plan/${params.plan_path}`,
{
Expand Down
78 changes: 68 additions & 10 deletions src/resources/Payment/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface IVoucherInfoResponse {
code: PlanCode
group_code: PlanGroupCode
hd_avail: PlanDiskSize
simulated_expiration: PlanExpirationDate
simulated_expiration?: PlanExpirationDate
}
new_remaining_days: number
}
Expand Down Expand Up @@ -112,26 +112,84 @@ export type PaymentProviderName = PaymentProvider['provider']

export type PaymentType = PaymentProvider['type']

export type PaymentOption = {
name: PaymentType
suitable_plan_types: (PlanType | 'trial')[]
default?: boolean
discount_percent: number
}

export interface IPaymentOptionsResponse {
options: PaymentOption[]
}

export interface IChangePlanRequestParams {
plan_path: string
payment_type: PaymentType
coupon_code?: string
confirmation_code?: string
}

export interface IChangePlanGetResponse {}
export interface IChangePlanGetResponse {
current_plan: {
plan_type?: PlanType
subscription_payment_provider?: PaymentProviderName
}
target_plan: {
price: number
plan_type: PlanType
period_days: number
plan_code: PlanCode
plan_name: PlanName
hd_avail: PlanDiskSize
simulated_expiration?: PlanExpirationDate
new_code: PlanCode
is_trial_subscription: boolean
subscription_trial_period?: number
}
Paddle: {
charge_amount: number
currency: string
next_billing_date: string
}
Fastspring: {
prorated_amount: number
refund_amount: number
charge_amount: number
currency: string
}
new_remaining_days: number
prorated: number
credit: number
charge_amount: boolean
currency: string
is_product_change: boolean
discount?: {
discount: number
type: 'percentage' | 'amount'
}
}

export interface IChangePlanPostResponse {
type ChangePlanURLsResponse = {
urls: PaymentProvider[]
}

export type PaymentOption = {
name: PaymentType
suitable_plan_types: (PlanType | 'trial')[]
default?: boolean
discount_percent: number
type ChangePlanConfirmationResponse = {
confirmation: true
}

export interface IPaymentOptionsResponse {
options: PaymentOption[]
type ChangePlanSubscriptionUpgradeDowngradeResponse = {
charged_amount: string
next_payment: {
amount: string
billing_date: string
}
}

type ChangePlanEmptyResponse = {}

export type IChangePlanPostResponse =
| ChangePlanURLsResponse
| ChangePlanConfirmationResponse
| ChangePlanSubscriptionUpgradeDowngradeResponse
| ChangePlanEmptyResponse

0 comments on commit d639035

Please sign in to comment.