From 19a2e54a127a43724167a224e793d6b39d4caef2 Mon Sep 17 00:00:00 2001 From: meow12 Date: Fri, 28 May 2021 13:14:47 +0300 Subject: [PATCH] feat(payments): create apple subscription create apple subscription --- src/components/payments.js | 28 ++++++++++++++++++++++++++++ src/components/push.js | 8 ++------ src/routes.js | 2 ++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/components/payments.js b/src/components/payments.js index 4ffa7ec..56b31ea 100644 --- a/src/components/payments.js +++ b/src/components/payments.js @@ -413,6 +413,34 @@ export async function createSubscription({ return response; } +export async function createAppStoreSubscription({ + secretKey, + customerId, + planId, + receipt, +}) { + const response = await server.loadJson( + `${ + Config.apiUrl + }${Endpoints.PROJECT.PAYMENTS.SUBSCRIPTIONS.CREATE_APP_STORE(customerId)}`, + { + method: 'POST', + headers: { + 'X-CM-ProjectId': Config.projectId, + Authorization: `Bearer ${secretKey || Config.secretKey}`, + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + planId, + receipt, + }), + } + ); + + return response; +} + export async function updateSubscription({ secretKey, id, diff --git a/src/components/push.js b/src/components/push.js index dd882f3..b473915 100644 --- a/src/components/push.js +++ b/src/components/push.js @@ -157,11 +157,7 @@ export async function updateDevice({ return response; } -export async function updateDeviceUser({ - secretKey, - idOrKey, - userId, -}) { +export async function updateDeviceUser({secretKey, idOrKey, userId}) { const response = await server.loadJson( `${Config.apiUrl}${Endpoints.PROJECT.NOTIFICATIONS.PUSH.UPDATE_DEVICE_USER( idOrKey @@ -175,7 +171,7 @@ export async function updateDeviceUser({ 'Content-Type': 'application/json', }, body: JSON.stringify({ - userId + userId, }), } ); diff --git a/src/routes.js b/src/routes.js index e2028ce..3cb15bc 100644 --- a/src/routes.js +++ b/src/routes.js @@ -148,6 +148,8 @@ export const CONFIG = { SUBSCRIPTIONS: { CREATE: (customerId) => `/v2/payments/customers/${customerId}/subscriptions`, + CREATE_APP_STORE: (customerId) => + `/v2/payments/customers/${customerId}/subscriptions/apple`, UPDATE: (customerId, id) => `/v2/payments/customers/${customerId}/subscriptions/${id}`, CHANGE: (customerId, id) =>