Menu

Pay & Play SDK

Getting Started

Before you can begin, you need a working API_KEY and API_SECRET which can be generated from https://www.pbapp.net/.

Dependencies

We have 4 dependencies project; ObjectMapper, Alamofire, SAMKeychain, MBProgressHUD. Which we manage dependencies by using Cocoapods ( https://cocoapods.org/. )

What is CocoaPods?

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods
                        

Step 1: Declare Dependency

To integrate Pay & Play into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
target '<Your Target Name>' do
    pod ‘ObjectMapper’
    pod ‘Alamofire’
    pod ‘SAMKeychain’
    pod ‘MBProgressHUD'
end
                        

Step 2: Install Dependency

Then, run the following command:

$ pod install
                        

Important : After that you have to access view project via <Your Project Name>.workspace instead.

Step 3: Drag and Drop Pay & Play Framework

Drag and drop PayAndPlaySDK.framework into your project. Make sure it was add into embedded Binaries.

Step 4: Call Pay & Play function

The code below demonstrate how we can use pay and play function in exciting ViewController.

  • 4.1 Import the SDK in the view controller from which you want to use it.

    import PayAndPlaySDK
                                    

  • 4.2 Declare apiKey and apiSecret which you generate from https://www.pbapp.net/

    let apiKey:String! = "xxxxxxxxx"
    let apiSecret:String! = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
    let templateId = "reward"
                                    

  • 4.3 Call to present play (spin wheel function). To do that there are 2 class methods to call: initWithPlayerId(_:apiKey:apiSecret:) and presentFromViewController(_:delegate:)

    let playerId = "testPlayer"
    PayAndPlaySDK.initWithPlayerId(playerId, apiKey: apiKey, apiSecret:apiSecret)
    PayAndPlaySDK.setEmailTemplateId(templateId)
    PayAndPlaySDK.presentFromViewController(self, delegate: self)
                                    

  • 4.4 You should provide a view controller from where to present the SDK as well as a delegate that will receive the events from the SDK.

    The possible events are:

    payAndPlaySDKDidReceiveRewardAndWillClose()
    
    payAndPlaySDKDidInputEmailAndWillClose()
    
    payAndPlaySDKDidTapCloseButton()
                                    

Example:

import UIKit
import PayAndPlaySDK

class ViewController: UIViewController, PayAndPlaySDKDelegate {
    // Declare apiKey and apiSecret which you generate from https://www.pbapp.net/.
    let apiKey:String! = "xxxxxxxxx"
    let apiSecret:String! = "xxxxxxxxxxxxxxxxxxxxxxxxxx"
    @IBAction func onpay(sender: AnyObject) {
        let playerId = "testPlayer"
        PayAndPlaySDK.initWithPlayerId(playerId, apiKey: apiKey, apiSecret:
apiSecret)
        PayAndPlaySDK.presentFromViewController(self, delegate: self)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    
    //MARK:- PayAndPlaySDK Delegate
    func payAndPlaySDKDidInputEmailAndWillClose() {
        //This delegate will be called after a new user has inputed his email and the SDK is about to be dismissed
        print("User did input email and SDK will dismiss")
    }

    func payAndPlaySDKDidReceiveRewardAndWillClose() {
        //This delegate will be called if the user is an existing user so he doesn't need to input his email and the SDK will dismiss after he received the reward
        print("User did receive reward and SDK will dismiss")
    }

    func payAndPlaySDKDidTapCloseButton() {
        //This delegate will be called when a user tap the close button
        print("User did tap close button")
    }
}
                            

What’s it looks like?