Skip to content

Commit a69dd87

Browse files
authored
Merge pull request #754 from inplayer-org/feature/subscription-plan-switch
New Subscribe method that changes the subscription plan
2 parents d0e5d11 + 82abf0f commit a69dd87

File tree

8 files changed

+76
-1
lines changed

8 files changed

+76
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Change Log
22

33
All notable changes to this project will be documented in this file.
4+
# [3.12.5] - 03-17-2022
5+
6+
### Changes
7+
8+
- Add new method in Subscription that changes the existing subscription plan. The change can either be a downgrade or an upgrade.
49

510
# [3.12.4] - 03-17-2022
611

index.d.ts

+13
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,15 @@ export declare interface CancelSubscription {
850850
status: string;
851851
timestamp: number;
852852
}
853+
854+
export interface ChangeSubscriptionPlanRequestBody {
855+
access_fee_id: number;
856+
inplayer_token: string;
857+
}
858+
859+
export interface ChangeSubscriptionPlanResponse {
860+
message: string;
861+
}
853862
export declare class Subscription {
854863
// eslint-disable-next-line no-shadow
855864
constructor(config: Record<string, unknown>, Account: Account);
@@ -866,6 +875,9 @@ export declare class Subscription {
866875
createSubscription(
867876
data: CreateSubscriptionData
868877
): Promise<AxiosResponse<CommonResponse>>;
878+
changeSubscriptionPlan(
879+
data: ChangeSubscriptionPlanRequestBody
880+
): Promise<AxiosResponse<ChangeSubscriptionPlanResponse>>;
869881
}
870882

871883
export interface DiscountData {
@@ -939,6 +951,7 @@ export interface ApiEndpoints {
939951
getSubscription: (id: string) => string;
940952
subscribe: string;
941953
cancelSubscription: (url: string) => string;
954+
changeSubscriptionPlan: (accessFeeId: number, inplayerToken: string) => string;
942955
// Voucher
943956
getDiscount: string;
944957
// Branding

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inplayer-org/inplayer.js",
3-
"version": "3.12.4",
3+
"version": "3.12.5",
44
"author": "InPlayer",
55
"license": "MIT",
66
"description": "A Javascript SDK for Inplayer's RESTful API",

src/constants/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export const API = {
9999
cancelSubscription: (url: string): string => `${url}`,
100100
subscribe: '/subscriptions',
101101
subscribeV2: '/v2/subscriptions',
102+
subscriptionPlanChange: '/v2/subscriptions/stripe:switch',
102103

103104
// Vouchers
104105
getDiscount: '/vouchers/discount',

src/endpoints/subscription.ts

+42
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
IdealPaymentRequestBody,
99
GetDefaultCard,
1010
SetDefaultCard,
11+
ChangeSubscriptionPlanRequestBody,
12+
ChangeSubscriptionPlanResponse,
1113
} from '../models/ISubscription';
1214
import { CommonResponse } from '../models/CommonInterfaces';
1315
import { ApiConfig, Request } from '../models/Config';
@@ -248,6 +250,46 @@ class Subscription extends BaseExtend {
248250
});
249251
}
250252

253+
/**
254+
* Changes the subscription plan for a given asset.
255+
* @method post
256+
* @async
257+
* @param {Object} data - {
258+
* access_fee_id: number,
259+
* inplayer_token: number
260+
* }
261+
* @example
262+
* InPlayer.Subscription
263+
* .changeSubscriptionPlan({
264+
* access_fee_id: 1,
265+
* inplayer_token: 'S-xxxxx-ST'
266+
* }
267+
* )
268+
* .then(data => console.log(data));
269+
* @return {Object}
270+
*/
271+
async changeSubscriptionPlan({
272+
access_fee_id,
273+
inplayer_token,
274+
}: {
275+
access_fee_id: number,
276+
inplayer_token: string,
277+
}): Promise<AxiosResponse<ChangeSubscriptionPlanResponse>> {
278+
const body: ChangeSubscriptionPlanRequestBody = {
279+
access_fee_id,
280+
inplayer_token,
281+
};
282+
283+
const tokenObject = await this.request.getToken();
284+
285+
return this.request.authenticatedPost(API.subscriptionPlanChange, qs.stringify(body), {
286+
headers: {
287+
Authorization: `Bearer ${tokenObject.token}`,
288+
'Content-Type': 'application/x-www-form-urlencoded',
289+
},
290+
});
291+
}
292+
251293
/**
252294
* Process a request for direct debit subscribe
253295
* @method directDebitSubscribe

src/models/Config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface ApiEndpoints {
7373
cancelSubscription: (url: string) => string;
7474
subscribe: string;
7575
subscribeV2: string;
76+
changeSubscriptionPlan: (access_fee_id: number, inplayer_token: string) => string;
7677
// Voucher
7778
getDiscount: string;
7879
// Restrictions

src/models/IAsset&Access.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface Item {
3434
template_id: number | null;
3535
created_at: number;
3636
update_at: number;
37+
plan_switch_enabled: boolean;
3738
}
3839

3940
export interface AccessType {

src/models/ISubscription.ts

+12
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ export interface CreateSubscriptionRequestBody {
8282
is_gift?: boolean;
8383
}
8484

85+
export interface ChangeSubscriptionPlanRequestBody {
86+
access_fee_id: number;
87+
inplayer_token: string;
88+
}
89+
8590
export interface IdealPaymentRequestBody {
8691
payment_method: 'ideal';
8792
access_fee_id: number;
@@ -119,6 +124,10 @@ export interface SetDefaultCardPerCurrencyData {
119124
currency: string;
120125
}
121126

127+
export interface ChangeSubscriptionPlanResponse {
128+
message: string;
129+
}
130+
122131
export interface Subscription extends BaseExtend {
123132
getSubscriptions(
124133
page?: number,
@@ -131,6 +140,9 @@ export interface Subscription extends BaseExtend {
131140
createSubscription(
132141
data: CreateSubscriptionData
133142
): Promise<AxiosResponse<CommonResponse>>;
143+
changeSubscriptionPlan(
144+
data: ChangeSubscriptionPlanRequestBody
145+
): Promise<AxiosResponse<ChangeSubscriptionPlanResponse>>;
134146
directDebitSubscribe: (
135147
data: DirectDebitData
136148
) => Promise<AxiosResponse<CommonResponse>>;

0 commit comments

Comments
 (0)