Skip to content

Commit 1f9f1ed

Browse files
committed
Adding method to configure payment blocks
1 parent e8b6627 commit 1f9f1ed

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Classes/SCPStoreKitManager.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ typedef void(^PaymentTransactionStateRestored)(NSArray *transactions);
2828

2929
- (void)requestProductsWithIdentifiers:(NSSet *)productsSet productsReturnedSuccessfully:(ProductsReturnedSuccessfully)productsReturnedSuccessfullyBlock invalidProducts:(InvalidProducts)invalidProductsBlock failure:(Failure)failureBlock;
3030

31+
- (void)configurePaymentTransactionStatePurchasing:(PaymentTransactionStatePurchasing)paymentTransactionStatePurchasingBlock paymentTransactionStatePurchased:(PaymentTransactionStatePurchased)paymentTransactionStatePurchasedBlock paymentTransactionStateFailed:(PaymentTransactionStateFailed)paymentTransactionStateFailedBlock paymentTransactionStateRestored:(PaymentTransactionStateRestored)paymentTransactionStateRestoredBlock failure:(Failure)failureBlock;
32+
33+
/**
34+
* Only if configure payment transaction blocks before calling that method
35+
*
36+
* @param product the product to buy
37+
*/
38+
- (void)requestPaymentForProduct:(SKProduct *)product;
39+
3140
- (void)requestPaymentForProduct:(SKProduct *)product paymentTransactionStatePurchasing:(PaymentTransactionStatePurchasing)paymentTransactionStatePurchasingBlock paymentTransactionStatePurchased:(PaymentTransactionStatePurchased)paymentTransactionStatePurchasedBlock paymentTransactionStateFailed:(PaymentTransactionStateFailed)paymentTransactionStateFailedBlock paymentTransactionStateRestored:(PaymentTransactionStateRestored)paymentTransactionStateRestoredBlock failure:(Failure)failureBlock;
3241

3342
- (void)restorePurchasesPaymentTransactionStateRestored:(PaymentTransactionStateRestored)paymentTransactionStateRestoredBlock paymentTransactionStateFailed:(PaymentTransactionStateFailed)paymentTransactionStateFailedBlock failure:(Failure)failureBlock;

Classes/SCPStoreKitManager.m

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,32 @@ - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProdu
8282
}
8383
}
8484

85+
- (void)configurePaymentTransactionStatePurchasing:(PaymentTransactionStatePurchasing)paymentTransactionStatePurchasingBlock paymentTransactionStatePurchased:(PaymentTransactionStatePurchased)paymentTransactionStatePurchasedBlock paymentTransactionStateFailed:(PaymentTransactionStateFailed)paymentTransactionStateFailedBlock paymentTransactionStateRestored:(PaymentTransactionStateRestored)paymentTransactionStateRestoredBlock failure:(Failure)failureBlock {
86+
87+
self.paymentTransactionStatePurchasingBlock = paymentTransactionStatePurchasingBlock;
88+
self.paymentTransactionStatePurchasedBlock = paymentTransactionStatePurchasedBlock;
89+
self.paymentTransactionStateFailedBlock = paymentTransactionStateFailedBlock;
90+
self.paymentTransactionStateRestoredBlock = paymentTransactionStateRestoredBlock;
91+
self.failureBlock = failureBlock;
92+
}
93+
94+
- (void)requestPaymentForProduct:(SKProduct *)product {
95+
SKPayment *payment = [SKPayment paymentWithProduct:product];
96+
97+
if([SKPaymentQueue canMakePayments])
98+
{
99+
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
100+
[[SKPaymentQueue defaultQueue] addPayment:payment];
101+
}
102+
else
103+
{
104+
if(failureBlock)
105+
{
106+
failureBlock([NSError errorWithDomain:SCPStoreKitDomain code:SCPErrorCodePaymentQueueCanNotMakePayments errorDescription:@"SKPaymentQueue can not make payments" errorFailureReason:@"Has the SKPaymentQueue got any uncompleted purchases?" errorRecoverySuggestion:@"Finish all transactions"]);
107+
}
108+
}
109+
}
110+
85111
- (void)requestPaymentForProduct:(SKProduct *)product paymentTransactionStatePurchasing:(PaymentTransactionStatePurchasing)paymentTransactionStatePurchasingBlock paymentTransactionStatePurchased:(PaymentTransactionStatePurchased)paymentTransactionStatePurchasedBlock paymentTransactionStateFailed:(PaymentTransactionStateFailed)paymentTransactionStateFailedBlock paymentTransactionStateRestored:(PaymentTransactionStateRestored)paymentTransactionStateRestoredBlock failure:(Failure)failureBlock
86112
{
87113
self.paymentTransactionStatePurchasingBlock = paymentTransactionStatePurchasingBlock;

0 commit comments

Comments
 (0)