Skip to content
Merged
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
13 changes: 8 additions & 5 deletions Parse/PFPurchase.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

PF_ASSUME_NONNULL_BEGIN

typedef void (^PFPurchaseProductObservationBlock)(SKPaymentTransaction *transaction);
typedef void (^PFPurchaseBuyProductResultBlock)(NSError *PF_NULLABLE_S error);
typedef void (^PFPurchaseDownloadAssetResultBlock)(NSString *PF_NULLABLE_S filePath, NSError *PF_NULLABLE_S error);

/*!
`PFPurchase` provides a set of APIs for working with in-app purchases.

Expand All @@ -35,16 +39,15 @@ PF_ASSUME_NONNULL_BEGIN
@param productIdentifier the product identifier
@param block The block to be run when buying a product.
*/
+ (void)addObserverForProduct:(NSString *)productIdentifier
block:(void(^)(SKPaymentTransaction *transaction))block;
+ (void)addObserverForProduct:(NSString *)productIdentifier block:(PFPurchaseProductObservationBlock)block;

/*!
@abstract *Asynchronously* initiates the purchase for the product.

@param productIdentifier the product identifier
@param block the completion block.
*/
+ (void)buyProduct:(NSString *)productIdentifier block:(void(^)(NSError *error))block;
+ (void)buyProduct:(NSString *)productIdentifier block:(PFPurchaseBuyProductResultBlock)block;

/*!
@abstract *Asynchronously* download the purchased asset, which is stored on Parse's server.
Expand All @@ -55,7 +58,7 @@ PF_ASSUME_NONNULL_BEGIN
@param completion the completion block.
*/
+ (void)downloadAssetForTransaction:(SKPaymentTransaction *)transaction
completion:(void(^)(NSString *filePath, NSError *error))completion;
completion:(PFPurchaseDownloadAssetResultBlock)completion;

/*!
@abstract *Asynchronously* download the purchased asset, which is stored on Parse's server.
Expand All @@ -67,7 +70,7 @@ PF_ASSUME_NONNULL_BEGIN
@param progress the progress block, which is called multiple times to reveal progress of the download.
*/
+ (void)downloadAssetForTransaction:(SKPaymentTransaction *)transaction
completion:(void(^)(NSString *filePath, NSError *error))completion
completion:(PFPurchaseDownloadAssetResultBlock)completion
progress:(PF_NULLABLE PFProgressBlock)progress;

/*!
Expand Down
9 changes: 5 additions & 4 deletions Parse/PFPurchase.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ @implementation PFPurchase
#pragma mark - Public
///--------------------------------------

+ (void)addObserverForProduct:(NSString *)productIdentifier block:(void(^)(SKPaymentTransaction *))block {
+ (void)addObserverForProduct:(NSString *)productIdentifier block:(PFPurchaseProductObservationBlock)block {
// We require the following method to run on the main thread because we want to add the observer
// *after* all products handlers have been added. Developers might be calling this method multiple
// times; and if the observer is added after the first call, the observer might not know how to
Expand All @@ -37,7 +37,7 @@ + (void)addObserverForProduct:(NSString *)productIdentifier block:(void(^)(SKPay
[[Parse _currentManager].purchaseController.transactionObserver handle:productIdentifier block:block];
}

+ (void)buyProduct:(NSString *)productIdentifier block:(void(^)(NSError *))completion {
+ (void)buyProduct:(NSString *)productIdentifier block:(PFPurchaseBuyProductResultBlock)completion {
[[[self _purchaseController] buyProductAsyncWithIdentifier:productIdentifier] continueWithBlock:^id(BFTask *task) {
if (completion) {
completion(task.error);
Expand All @@ -50,12 +50,13 @@ + (void)restore {
[[self _purchaseController].paymentQueue restoreCompletedTransactions];
}

+ (void)downloadAssetForTransaction:(SKPaymentTransaction *)transaction completion:(PFStringResultBlock)completion {
+ (void)downloadAssetForTransaction:(SKPaymentTransaction *)transaction
completion:(PFPurchaseDownloadAssetResultBlock)completion {
[self downloadAssetForTransaction:transaction completion:completion progress:nil];
}

+ (void)downloadAssetForTransaction:(SKPaymentTransaction *)transaction
completion:(PFStringResultBlock)completion
completion:(PFPurchaseDownloadAssetResultBlock)completion
progress:(PFProgressBlock)progress {
@weakify(self);
[[[PFUser _getCurrentUserSessionTokenAsync] continueWithBlock:^id(BFTask *task) {
Expand Down