Switch to /api/v1/subscriptions/options method
This commit is contained in:
parent
86945aa057
commit
e6b0d51dfe
3 changed files with 30 additions and 23 deletions
|
@ -1,10 +1,11 @@
|
|||
import { BACKEND_URL } from "@/constants"
|
||||
import { http } from "./common"
|
||||
import { User } from "./users"
|
||||
|
||||
export interface SubscriptionOption {
|
||||
type: string;
|
||||
price: number | null;
|
||||
payout_address: number | null;
|
||||
payout_address: string | null;
|
||||
}
|
||||
|
||||
export async function getSubscriptionOptions(
|
||||
|
@ -23,6 +24,24 @@ export async function getSubscriptionOptions(
|
|||
}
|
||||
}
|
||||
|
||||
export async function registerSubscriptionOption(
|
||||
authToken: string,
|
||||
subscriptionOption: SubscriptionOption,
|
||||
): Promise<User> {
|
||||
const url = `${BACKEND_URL}/api/v1/subscriptions/options`
|
||||
const response = await http(url, {
|
||||
method: "POST",
|
||||
authToken,
|
||||
json: subscriptionOption,
|
||||
})
|
||||
const data = await response.json()
|
||||
if (response.status !== 200) {
|
||||
throw new Error(data.message)
|
||||
} else {
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
export interface SubscriptionDetails {
|
||||
id: number,
|
||||
expires_at: string,
|
||||
|
|
|
@ -7,6 +7,7 @@ import { ethereumAddressMatch, EthereumSignature } from "@/utils/ethereum"
|
|||
import { floatToBigNumber, roundBigNumber } from "@/utils/numbers"
|
||||
import { http } from "./common"
|
||||
import { Contracts, getContract } from "./contracts"
|
||||
import { registerSubscriptionOption } from "./subscriptions-common"
|
||||
import { Profile, User } from "./users"
|
||||
|
||||
const SECONDS_IN_DAY = 3600 * 24
|
||||
|
@ -92,18 +93,11 @@ export async function configureSubscriptions(
|
|||
export async function onSubscriptionsEnabled(
|
||||
authToken: string,
|
||||
): Promise<User> {
|
||||
const url = `${BACKEND_URL}/api/v1/subscriptions/enable`
|
||||
const response = await http(url, {
|
||||
method: "POST",
|
||||
authToken,
|
||||
json: { type: "ethereum" },
|
||||
return await registerSubscriptionOption(authToken, {
|
||||
type: "ethereum",
|
||||
price: null,
|
||||
payout_address: null,
|
||||
})
|
||||
const data = await response.json()
|
||||
if (response.status !== 200) {
|
||||
throw new Error(data.message)
|
||||
} else {
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
export class SubscriptionConfig {
|
||||
|
|
|
@ -2,6 +2,7 @@ import { BigNumber } from "@ethersproject/bignumber"
|
|||
|
||||
import { BACKEND_URL } from "@/constants"
|
||||
import { http } from "./common"
|
||||
import { registerSubscriptionOption } from "./subscriptions-common"
|
||||
import {
|
||||
formatAmount,
|
||||
getPricePerMonth as _getPricePerMonth,
|
||||
|
@ -24,18 +25,11 @@ export async function enableMoneroSubscriptions(
|
|||
price: number,
|
||||
payoutAddress: string,
|
||||
): Promise<User> {
|
||||
const url = `${BACKEND_URL}/api/v1/subscriptions/enable`
|
||||
const response = await http(url, {
|
||||
method: "POST",
|
||||
authToken,
|
||||
json: { type: "monero", price, payout_address: payoutAddress },
|
||||
return await registerSubscriptionOption(authToken, {
|
||||
type: "monero",
|
||||
price,
|
||||
payout_address: payoutAddress,
|
||||
})
|
||||
const data = await response.json()
|
||||
if (response.status !== 200) {
|
||||
throw new Error(data.message)
|
||||
} else {
|
||||
return data
|
||||
}
|
||||
}
|
||||
|
||||
export interface Invoice {
|
||||
|
|
Loading…
Reference in a new issue