Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ + (NSDictionary *)getMapFromSKStorefront:(SKStorefront *)storefront

+ (SKPaymentDiscount *)getSKPaymentDiscountFromMap:(NSDictionary *)map
withError:(NSString **)error {
if (!map || map.count <= 0) {
if (!map || [map isKindOfClass:[NSNull class]] || map.count <= 0) {
return nil;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ + (SKPaymentDiscount *)getSKPaymentDiscountFromMap:(NSDictionary *)map
return nil;
}

if (!timestamp || ![timestamp isKindOfClass:NSNumber.class] || [timestamp intValue] <= 0) {
if (!timestamp || ![timestamp isKindOfClass:NSNumber.class] || timestamp <= 0) {
if (error) {
*error = @"When specifying a payment discount the 'timestamp' field is mandatory.";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ class InAppPurchaseStoreKitPlatform extends InAppPurchasePlatform {
return true; // There's no error feedback from iOS here to return.
}

static Future<bool> buyNonConsumableWithDiscount(
{required PurchaseParam purchaseParam, SKPaymentDiscountWrapper? discount}) async {
await _skPaymentQueueWrapper.addPayment(SKPaymentWrapper(
Comment on lines +84 to +86
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it a static method while it is using an instance variable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would imagine the discount can be part of the PurchaseParam

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cyanglaz the instance variable is also static. I agree it is not the best option. I merely wanted a working solution to open a pull request with. Then have a discussion about how to resolve it, or have it resolved by someone from the maintainers.

If it's part of PurchaseParam, this method would not be needed at all but I presume there should be also Android counterpart . In the original Pull request I saw only iOS implementation. I don't know how the Android offers work (if there are any).

productIdentifier: purchaseParam.productDetails.id,
quantity: purchaseParam is AppStorePurchaseParam ? purchaseParam.quantity : 1,
applicationUsername: purchaseParam.applicationUserName,
simulatesAskToBuyInSandbox: purchaseParam is AppStorePurchaseParam && purchaseParam.simulatesAskToBuyInSandbox,
requestData: null,
paymentDiscount: discount,
));

return true; // There's no error feedback from iOS here to return.
}

@override
Future<bool> buyConsumable(
{required PurchaseParam purchaseParam, bool autoConsume = true}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,8 @@ class SKPaymentWrapper {
'applicationUsername': applicationUsername,
'requestData': requestData,
'quantity': quantity,
'simulatesAskToBuyInSandbox': simulatesAskToBuyInSandbox
'simulatesAskToBuyInSandbox': simulatesAskToBuyInSandbox,
'paymentDiscount': paymentDiscount?.toMap(),
};
}

Expand Down