PFPurchase
Objective-C
@interface PFPurchase : NSObject
Swift
class PFPurchase : NSObject
PFPurchase is the entry point for PurchaseFly.framework. It should be instantiated as soon as app starts.
Warning
Only one instance of PFPurchase should be instantiated at a time! Use the configure method to let the framework handle the singleton instance for you.-
Declaration
Objective-C
@property (class, nonatomic, readonly) PFPurchase *_Nonnull sharedPurchase;Swift
class var shared: PFPurchase { get }Return Value
A singleton
PFPurchaseobject. Call this after a configure method to access the singleton. -
Delegate for
PFPurchaseinstance. The delegate is responsible for handling changes to any group’s subscriptionDeclaration
Objective-C
@property (nonatomic, weak) id<PFPurchaseDelegate> _Nullable delegate;Swift
weak var delegate: PFPurchaseDelegate? { get set } -
Enable debug logging
Declaration
Objective-C
@property (class, nonatomic) BOOL debugLogsEnabled;Swift
class var debugLogsEnabled: Bool { get set } -
Set this to true if you are passing in an appUserID and you want the user to obtain a purchase that he has made with a different store account or in a different device. This is false by default. This must be set before
-[PFPurchase trackUser:withCompletionBlock:]is calledDeclaration
Objective-C
@property (nonatomic) BOOL allowPurchaseSharing;Swift
var allowPurchaseSharing: Bool { get set } -
Configures an instance of the PurchaseFly SDK with a specified API key and API Secret. The instance will be set as a singleton. You should access the singleton instance using [PFPurchase sharedPurchase]
Note
Use this initializer and it will generate a unique identifier for the current device and persist it to
NSUserDefaultsDeclaration
Objective-C
+ (nonnull instancetype)configWithAPIKey:(nonnull NSString *)apiKey withAPISecret:(nonnull NSString *)apiSecret;Swift
class func config(withAPIKey apiKey: String, withAPISecret apiSecret: String) -> SelfParameters
apiKeyThe API Key generated for your app from https://app.purchasefly.com
apiSecretThe API Secret generated for your app from https://app.purchasefly.com
Return Value
An instantiated
PFPurchaseobject that has been set as a singleton -
Configures an instance of the PurchaseFly SDK with a specified API key and API Secret and app’s user id if available. The instance will be set as a singleton. You should access the singleton instance using [PFPurchase sharedPurchase]
Note
Use this initializer and it will generate a unique identifier for the current device and persist it to
NSUserDefaultsDeclaration
Objective-C
+ (nonnull instancetype)configWithAPIKey:(nonnull NSString *)apiKey withAPISecret:(nonnull NSString *)apiSecret withUserID:(nonnull NSString *)userID;Swift
class func config(withAPIKey apiKey: String, withAPISecret apiSecret: String, withUserID userID: String) -> SelfParameters
apiKeyThe API Key generated for your app from https://app.purchasefly.com
apiSecretThe API Secret generated for your app from https://app.purchasefly.com
userIDIf app has unique user ID it cna be passed here
Return Value
An instantiated
PFPurchaseobject that has been set as a singleton -
Indicates whether the user is allowed to make payments
Declaration
Objective-C
+ (BOOL)canMakePayments;Swift
class func canMakePayments() -> Bool -
Get all consumable type products
Declaration
Objective-C
- (void)getAllConsumableProducts: (PFReceiveConsumablesBlock _Nullable)completion;Swift
func getAllConsumableProducts(_ completion: PFReceiveConsumablesBlock? = nil)Parameters
completionA completion block that is called when the product fetching completes
-
Purchases the passed
PFPackageInfo.Call this method when a user has decided to purchase a product. Only call this in direct response to user input.
From here
PFPurchasewill handle the purchase withStoreKitand call thePFPurchaseCompletedBlock.Note
You do not need to finish the transaction yourself in the completion callback, Purchases will handle this for you.Declaration
Objective-C
- (void)makePurchaseWithPackageInfo:(nonnull PFPackageInfo *)package withCompletionBlock: (PFPurchaseCompletedBlock _Nullable)completion;Swift
func make(with package: PFPackageInfo, withCompletionBlock completion: PFPurchaseCompletedBlock? = nil)Parameters
packageThe
PFPackageInfopackagecompletionA completion block that is called when the purchase completes. If the purchase was successful there will be a
PFTransactionand updated groups info. If the purchase was not successful, there will be anNSError. If the user cancelled,userCancelledwill beYES. -
Purchases the passed
PFProduct.Call this method when a user has decided to purchase a product. Only call this in direct response to user input.
From here
PFPurchasewill handle the purchase withStoreKitand call thePFPurchaseCompletedBlock.Note
You do not need to finish the transaction yourself in the completion callback, Purchases will handle this for you.Declaration
Objective-C
- (void)makePurchaseWithProduct:(nonnull PFProduct *)product withCompletionBlock:(PFPurchaseCompletedBlock _Nullable)completion;Swift
func make(with product: PFProduct, withCompletionBlock completion: PFPurchaseCompletedBlock? = nil)Parameters
productThe
PFProductproductcompletionA completion block that is called when the purchase completes. If the purchase was successful there will be a
PFTransactionand updated groups info. If the purchase was not successful, there will be anNSError. If the user cancelled,userCancelledwill beYES. -
Purchases the passed
PFProductwith promo fromPFDiscount.Call this method when a user has decided to purchase a product and you want to offer a promotional offer to the user. Only call this in direct response to user input.
From here
PFPurchasewill handle the purchase withStoreKitand call thePFPurchaseCompletedBlock.Note
You do not need to finish the transaction yourself in the completion callback, Purchases will handle this for you.Declaration
Objective-C
- (void)makePurchaseWithProduct:(nonnull PFProduct *)product withDiscount:(nonnull PFDiscount *)discount withCompletionBlock:(PFPurchaseCompletedBlock _Nullable)completion;Swift
func make(with product: PFProduct, with discount: PFDiscount, withCompletionBlock completion: PFPurchaseCompletedBlock? = nil)Parameters
productThe
PFProductproductdiscountThe
PFDiscountdiscountcompletionA completion block that is called when the purchase completes. If the purchase was successful there will be a
PFTransactionand updated groups info. If the purchase was not successful, there will be anNSError. If the user cancelled,userCancelledwill beYES. -
This method will post all purchases associated with the current App Store account to PurchaseFly. If the receipt is being used by an existing user, the current user will be aliased together with the existing user
Note
This may force your users to enter the App Store password so should only be performed on request of the user. Typically with a button in settings or near your purchase UI.
Declaration
Objective-C
- (void)restorePurchase:(PFReceiveGroupByNameBlock _Nullable)completion;Swift
func restore(_ completion: PFReceiveGroupByNameBlock? = nil)Parameters
completionA completion block that has updates groups info
-
Get updated groups info in array
Declaration
Objective-C
- (void)groups:(PFReceiveGroupsBlock _Nullable)completion;Swift
func groups(_ completion: PFReceiveGroupsBlock? = nil)Parameters
completionA completion block that has updated groups
-
Get dictionary of all the groups in the dashboard with their names as keys
Declaration
Objective-C
- (void)groupByName:(PFReceiveGroupByNameBlock _Nullable)completion;Swift
func group(byName completion: PFReceiveGroupByNameBlock? = nil)Parameters
completionA completion block that has updates groups info
-
Reset resets the token and user and initiates a new anonymous user.
Declaration
Objective-C
- (void)reset;Swift
func reset() -
Track user’s ID. If your application has unique user ID, you can use this method to track user in PurchaseFly system and access them in the dashboard.
If you want to get user’s purchases from a different store account, you must call this method after setting
allowPurchaseSharingoptionDeclaration
Objective-C
- (void)trackUser:(NSString *_Nullable)userID withCompletionBlock: (PFReceiveGroupByNameAndUserInfoBlock _Nullable)completion;Swift
func trackUser(_ userID: String?, withCompletionBlock completion: PFReceiveGroupByNameAndUserInfoBlock? = nil)Parameters
userIDUnique identifier of user
completionThis is called with updated user info and groups info
-
Get tracked user info
Declaration
Objective-C
- (void)userInfo:(PFReceiveUserInfoBlock _Nullable)completion;Swift
func userInfo(_ completion: PFReceiveUserInfoBlock? = nil)Parameters
completionA completion block that is called when the user fetching completes
-
Computes whether or not the product is eligible for either introductory or promotional discount offer
Declaration
Objective-C
- (void)checkDiscountEligibility:(nonnull NSString *)productId withDiscountType:(PFDiscountType)type withCompletion: (nonnull PFReceiveDiscountEligibilityBlock)completion;Swift
func checkDiscountEligibility(_ productId: String, with type: PFDiscountType, withCompletion completion: @escaping PFReceiveDiscountEligibilityBlock)Parameters
productIdProduct that discount is going to be offered for
typeThe type of the product, possible values are
PFDiscountTypecompletionA completion handler after eligibility is computed
View on GitHub
PFPurchase Class Reference