Skip to content

aplazame/ios-sdk

Repository files navigation

CocoaPods Compatible Carthage compatible

Aplazame

Installation

github "Aplazame/ios-sdk"

Then run carthage update.

Follow the current instructions in Carthage's README for up to date installation instructions.

Add the following to your Podfile:

pod 'Aplazame-iOS-SDK'

Then run pod install with CocoaPods 1.0 or newer.

How to use

First at all add the following permissions (Privacy - Camera Usage Description and Privacy - Photo Library Usage Description) to your main application info.plist:

<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME)</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>$(PRODUCT_NAME)</string>

Then you need to create an instance of APZPaymentContext with the APZConfig object:

let config = APZConfig(accessToken: token, environment: .sandbox)

let paymentContext = APZPaymentContext(config: APZConfig(accessToken: "your-token-here", environment: .sandbox | .production))

Now you can check if Aplazame is available for your order. The best way to do it is to call:

paymentContext.checkAvailability(amount: 12050, currency: "EUR") { (status) in
  switch status {
    case .available:
      // Enable checkout button for instance
    case .notAvailable, .undefined:
      // Hide the checkout button for instance
    }
  }

After this check you need to request the checkout presentation. AplazameSDK needs 3 objects ito do this:

  • checkout: it is the checkout id returned by Aplazame to your server.
  • delegate: class that will receive payment flow callbacks.
  • onReady: will be called when the checkout is ready to be presented.
// Start activity indicator
paymentContext.requestCheckout(checkout: checkout, delegate: self, onReady: { vc in
  // Stop activity indicator
  self.navigationController?.pushViewController(vc, animated: true)
})

or the SDK provides a helper method with a default presentation:

// Start activity indicator
paymentContext.requestCheckout(from: self, checkout: checkout_id, delegate: self, onPresent: {
     // Stop activity indicator       
})

Check the demo project to see an example of their use.

Next, you will need an object that conform to APZPaymentContextDelegate protocol. This object will receive the following calls:

extension ViewController: APZPaymentContextDelegate {
  func checkoutDidClose(checkoutVC: UIViewController, with reason: APZCheckoutCloseReason) {
    print("checkoutDidCloseWithReason \(reason.rawValue)")
    checkoutVC.dismiss(animated: true, completion: nil)
  }
    
  func checkoutStatusChanged(with status: APZCheckoutStatus) {
    print("checkoutStatusChanged \(status.rawValue)")
  }
}

License

Aplazame is Copyright (c) 2017 Aplazame, inc. It is free software, and may be redistributed under the terms specified in the LICENSE file.

About

https://aplazame.com/