Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/IapUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation
import StoreKit
import React
import React_Core

public func debugMessage(_ object: Any...) {
#if DEBUG
Expand Down
1 change: 1 addition & 0 deletions ios/RNIapIos.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ @interface RCT_EXTERN_MODULE (RNIapIos, NSObject)

RCT_EXTERN_METHOD(buyProduct:
(NSString*)sku
requestJSONString:(NSString*)requestJSONString
andDangerouslyFinishTransactionAutomatically:(BOOL)andDangerouslyFinishTransactionAutomatically
applicationUsername:(NSString*)applicationUsername
quantity:(NSInteger)quantity
Expand Down
37 changes: 22 additions & 15 deletions ios/RNIapIos.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React
import React_Core
import StoreKit

@objc(RNIapIos)
Expand Down Expand Up @@ -184,6 +184,7 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver

@objc public func buyProduct(
_ sku: String,
requestJSONString: String?,
andDangerouslyFinishTransactionAutomatically: Bool,
applicationUsername: String?,
quantity: Int,
Expand All @@ -197,23 +198,29 @@ class RNIapIos: RCTEventEmitter, SKRequestDelegate, SKPaymentTransactionObserver

let payment = SKMutablePayment(product: product)

if #available(iOS 12.2, tvOS 12.2, *) {
if let discountOffer = discountOffer, let identifier = discountOffer["identifier"], let keyIdentifier = discountOffer["keyIdentifier"], let nonce = discountOffer["nonce"], let signature = discountOffer["signature"], let timestamp = discountOffer["timestamp"] {
let discount = SKPaymentDiscount(
identifier: identifier,
keyIdentifier: keyIdentifier,
nonce: UUID(uuidString: nonce)!,
signature: signature,
timestamp: NSNumber(value: Int(timestamp)!))
payment.paymentDiscount = discount
}
}

if let applicationUsername = applicationUsername {
payment.applicationUsername = applicationUsername
}
if quantity > 0 {
payment.quantity = quantity

if let requestJSONString = requestJSONString {
let requestData = Data(requestJSONString.utf8)
payment.requestData = requestData
} else {
if #available(iOS 12.2, tvOS 12.2, *) {
if let discountOffer = discountOffer, let identifier = discountOffer["identifier"], let keyIdentifier = discountOffer["keyIdentifier"], let nonce = discountOffer["nonce"], let signature = discountOffer["signature"], let timestamp = discountOffer["timestamp"] {
let discount = SKPaymentDiscount(
identifier: identifier,
keyIdentifier: keyIdentifier,
nonce: UUID(uuidString: nonce)!,
signature: signature,
timestamp: NSNumber(value: Int(timestamp)!))
payment.paymentDiscount = discount
}
}

if quantity > 0 {
payment.quantity = quantity
}
}

SKPaymentQueue.default().add(payment)
Expand Down
1 change: 1 addition & 0 deletions ios/RNIapIosSk2.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ @interface RCT_EXTERN_MODULE (RNIapIosSk2, NSObject)

RCT_EXTERN_METHOD(buyProduct:
(NSString*)sku
requestJSONString:(NSString*)requestJSONString
andDangerouslyFinishTransactionAutomatically:(BOOL)andDangerouslyFinishTransactionAutomatically
appAccountToken:(NSString*)appAccountToken
quantity:(NSInteger)quantity
Expand Down
33 changes: 22 additions & 11 deletions ios/RNIapIosSk2.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Foundation
import React
import React_Core
import StoreKit

protocol Sk2Delegate {
Expand Down Expand Up @@ -33,6 +33,7 @@ protocol Sk2Delegate {

func buyProduct(
_ sku: String,
requestJSONString: String?,
andDangerouslyFinishTransactionAutomatically: Bool,
appAccountToken: String?,
quantity: Int,
Expand Down Expand Up @@ -155,6 +156,7 @@ class DummySk2: Sk2Delegate {

func buyProduct(
_ sku: String,
requestJSONString: String?,
andDangerouslyFinishTransactionAutomatically: Bool,
appAccountToken: String?,
quantity: Int,
Expand Down Expand Up @@ -330,6 +332,7 @@ class RNIapIosSk2: RCTEventEmitter, Sk2Delegate {

@objc public func buyProduct(
_ sku: String,
requestJSONString: String?,
andDangerouslyFinishTransactionAutomatically: Bool,
appAccountToken: String?,
quantity: Int,
Expand All @@ -339,6 +342,7 @@ class RNIapIosSk2: RCTEventEmitter, Sk2Delegate {
) {
delegate.buyProduct(
sku,
requestJSONString: requestJSONString,
andDangerouslyFinishTransactionAutomatically: andDangerouslyFinishTransactionAutomatically,
appAccountToken: appAccountToken,
quantity: quantity,
Expand Down Expand Up @@ -699,6 +703,7 @@ class RNIapIosSk2iOS15: Sk2Delegate {

public func buyProduct(
_ sku: String,
requestJSONString: String?,
andDangerouslyFinishTransactionAutomatically: Bool,
appAccountToken: String?,
quantity: Int,
Expand All @@ -712,18 +717,24 @@ class RNIapIosSk2iOS15: Sk2Delegate {
if let product = product {
do {
var options: Set<Product.PurchaseOption> = []
if quantity > -1 {
options.insert(.quantity(quantity))
}

let offerID = withOffer["offerID"]
let keyID = withOffer["keyID"]
let nonce = withOffer["nonce"]
let signature = withOffer["signature"]
let timestamp = withOffer["timestamp"]
if let requestJSONString = requestJSONString {
let requestData = Data(requestJSONString.utf8)
options.insert(Product.PurchaseOption.custom(key: "requestData", value: requestData))
} else {
if quantity > -1 {
options.insert(.quantity(quantity))
}

if let offerID = offerID, let keyID = keyID, let nonce = nonce, let nonce = UUID(uuidString: nonce), let signature = signature, let signature = signature.data(using: .utf8), let timestamp = timestamp, let timestamp = Int(timestamp) {
options.insert(.promotionalOffer(offerID: offerID, keyID: keyID, nonce: nonce, signature: signature, timestamp: timestamp ))
let offerID = withOffer["offerID"]
let keyID = withOffer["keyID"]
let nonce = withOffer["nonce"]
let signature = withOffer["signature"]
let timestamp = withOffer["timestamp"]

if let offerID = offerID, let keyID = keyID, let nonce = nonce, let nonce = UUID(uuidString: nonce), let signature = signature, let signature = signature.data(using: .utf8), let timestamp = timestamp, let timestamp = Int(timestamp) {
options.insert(.promotionalOffer(offerID: offerID, keyID: keyID, nonce: nonce, signature: signature, timestamp: timestamp ))
}
}
if let appAccountToken = appAccountToken, let appAccountToken = UUID(uuidString: appAccountToken) {
options.insert(.appAccountToken(appAccountToken))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"bootstrap": "yarn example && yarn && yarn example pods",
"gen:doc": "typedoc",
"build:plugin": "tsc --build plugin",
"clean:plugin": "expo-module clean plugin",
"clean:plugin": "node -e \"if (process.platform !== 'win32'){process.exit(1)} \" || expo-module clean plugin",
"lint:plugin": "eslint plugin/src/*"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions plugin/build/withIAP.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ const withIAPAndroid = (config, { paymentProvider }) => {
const withIAP = (config, props) => {
const paymentProvider = props?.paymentProvider ?? 'Play Store';
if (!hasPaymentProviderProperValue(paymentProvider)) {
config_plugins_1.WarningAggregator.addWarningAndroid('react-native-iap', `The payment provider '${paymentProvider}' is not supported. Please update your app.json file with one of the following supported values: 'Play Store', 'Amazon AppStore', or 'both'.`);
config_plugins_2.WarningAggregator.addWarningAndroid('react-native-iap', `The payment provider '${paymentProvider}' is not supported. Please update your app.json file with one of the following supported values: 'Play Store', 'Amazon AppStore', or 'both'.`);
return config;
}
try {
config = withIAPAndroid(config, { paymentProvider });
}
catch (error) {
config_plugins_1.WarningAggregator.addWarningAndroid('react-native-iap', `There was a problem configuring react-native-iap in your native Android project: ${error}`);
config_plugins_2.WarningAggregator.addWarningAndroid('react-native-iap', `There was a problem configuring react-native-iap in your native Android project: ${error}`);
}
return config;
};
exports.default = (0, config_plugins_2.createRunOncePlugin)(withIAP, pkg.name, pkg.version);
exports.default = (0, config_plugins_1.createRunOncePlugin)(withIAP, pkg.name, pkg.version);
6 changes: 6 additions & 0 deletions src/iap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ export const requestPurchase = (
appAccountToken,
quantity,
withOffer,
requestJSONString,
} = request;

if (andDangerouslyFinishTransactionAutomaticallyIOS) {
Expand All @@ -610,6 +611,7 @@ export const requestPurchase = (
const purchase = transactionSk2ToPurchaseMap(
await RNIapIosSk2.buyProduct(
sku,
requestJSONString,
andDangerouslyFinishTransactionAutomaticallyIOS,
appAccountToken,
quantity ?? -1,
Expand All @@ -620,6 +622,7 @@ export const requestPurchase = (
} else {
return RNIapIos.buyProduct(
sku,
requestJSONString,
andDangerouslyFinishTransactionAutomaticallyIOS,
appAccountToken,
quantity ?? -1,
Expand Down Expand Up @@ -753,6 +756,7 @@ export const requestSubscription = (
appAccountToken,
quantity,
withOffer,
requestJSONString,
} = request;

if (andDangerouslyFinishTransactionAutomaticallyIOS) {
Expand All @@ -767,6 +771,7 @@ export const requestSubscription = (
const purchase = transactionSk2ToPurchaseMap(
await RNIapIosSk2.buyProduct(
sku,
requestJSONString,
andDangerouslyFinishTransactionAutomaticallyIOS,
appAccountToken,
quantity ?? -1,
Expand All @@ -777,6 +782,7 @@ export const requestSubscription = (
} else {
return RNIapIos.buyProduct(
sku,
requestJSONString,
andDangerouslyFinishTransactionAutomaticallyIOS,
appAccountToken,
quantity ?? -1,
Expand Down
1 change: 1 addition & 0 deletions src/modules/ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type getAvailableItems = (

export type BuyProduct = (
sku: Sku,
requestJSONString: string | undefined,
andDangerouslyFinishTransactionAutomaticallyIOS: boolean,
applicationUsername: string | undefined,
quantity: number,
Expand Down
1 change: 1 addition & 0 deletions src/modules/iosSk2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type getAvailableItems = (

export type BuyProduct = (
sku: Sku,
requestJSONString: string | undefined,
andDangerouslyFinishTransactionAutomaticallyIOS: boolean,
applicationUsername: string | undefined,
quantity: number,
Expand Down
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export interface RequestPurchaseAndroid extends RequestPurchaseBaseAndroid {
export interface RequestPurchaseIOS {
sku: Sku;
andDangerouslyFinishTransactionAutomaticallyIOS?: boolean;
requestJSONString?: string;
/**
* UUID representing user account
*/
Expand Down
Loading