-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MINI-1737] - JS Mini app for IAP feature (#244)
* SDK & Bridge changes * No Redux pattern * Prettier fix * Refactor * Lint fix * SDK build fix * Refactor * Wrap for Listitem * Linting * Lint issue * Dispatch changes * Revert changes * Consume purchase. * Refactor * Prettify fix * Added IAP Error types * Update Consume status & refactor * Updated Node module to 14.18.0 * Lint * Error messages handling * Prettier
- Loading branch information
1 parent
d4caee6
commit 9e38e22
Showing
18 changed files
with
441 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
js-miniapp-bridge/src/types/error-types/in-app-purchase-errors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { MiniAppError, MiniAppJson } from './mini-app-error'; | ||
|
||
enum MiniAppInAppPurchaseErrorType { | ||
PurchaseFailedError = 'PurchaseFailedError', | ||
ConsumeFailedError = 'ConsumeFailedError', | ||
ProductNotFoundError = 'ProductNotFoundError', | ||
ProductPurchasedAlreadyError = 'ProductPurchasedAlreadyError', | ||
UserCancelledPurchaseError = 'UserCancelledPurchaseError', | ||
} | ||
|
||
export class PurchaseFailedError extends MiniAppError { | ||
constructor(public errorInput: MiniAppJson) { | ||
super(errorInput); | ||
Object.setPrototypeOf(this, PurchaseFailedError.prototype); | ||
this.message = 'Product Purchase failed, please try again later'; | ||
} | ||
} | ||
|
||
export class ConsumeFailedError extends MiniAppError { | ||
constructor(public errorInput: MiniAppJson) { | ||
super(errorInput); | ||
Object.setPrototypeOf(this, ConsumeFailedError.prototype); | ||
this.message = | ||
'Unable to consume the product, please make sure the product is purchased already'; | ||
} | ||
} | ||
|
||
export class ProductNotFoundError extends MiniAppError { | ||
constructor(public errorInput: MiniAppJson) { | ||
super(errorInput); | ||
Object.setPrototypeOf(this, ProductNotFoundError.prototype); | ||
this.message = | ||
'Unable to find the ProductId. Please make sure that the productId is registered in Google Play'; | ||
} | ||
} | ||
|
||
export class ProductPurchasedAlreadyError extends MiniAppError { | ||
constructor(public errorInput: MiniAppJson) { | ||
super(errorInput); | ||
Object.setPrototypeOf(this, ProductPurchasedAlreadyError.prototype); | ||
this.message = 'This Product is purchased already'; | ||
} | ||
} | ||
|
||
export class UserCancelledPurchaseError extends MiniAppError { | ||
constructor(public errorInput: MiniAppJson) { | ||
super(errorInput); | ||
Object.setPrototypeOf(this, UserCancelledPurchaseError.prototype); | ||
this.message = 'User cancelled the purchase'; | ||
} | ||
} | ||
|
||
export function parseInAppPurchaseError(json: MiniAppJson) { | ||
const errorType: MiniAppInAppPurchaseErrorType = | ||
MiniAppInAppPurchaseErrorType[ | ||
json.type as keyof typeof MiniAppInAppPurchaseErrorType | ||
]; | ||
switch (errorType) { | ||
case MiniAppInAppPurchaseErrorType.PurchaseFailedError: | ||
return new PurchaseFailedError(json); | ||
case MiniAppInAppPurchaseErrorType.ConsumeFailedError: | ||
return new ConsumeFailedError(json); | ||
case MiniAppInAppPurchaseErrorType.ProductNotFoundError: | ||
return new ProductNotFoundError(json); | ||
case MiniAppInAppPurchaseErrorType.ProductPurchasedAlreadyError: | ||
return new ProductPurchasedAlreadyError(json); | ||
case MiniAppInAppPurchaseErrorType.UserCancelledPurchaseError: | ||
return new UserCancelledPurchaseError(json); | ||
default: | ||
return undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
export interface Product { | ||
export interface ProductInfo { | ||
title: string; | ||
description: string; | ||
id: string; | ||
price: ProductPrice; | ||
productPriceInfo: ProductPrice; | ||
} | ||
|
||
export interface ProductPrice { | ||
currencyCode: string; | ||
price: string; | ||
} | ||
|
||
export interface PurchasedProduct { | ||
product: Product; | ||
export interface PurchasedProductInfo { | ||
productInfo: ProductInfo; | ||
transactionId: string; | ||
transactionDate: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.