Giter VIP home page Giter VIP logo

paymaya-ios-sdk-v2's Introduction

PayMayaSDK

The PayMaya iOS SDK is a library that allows you to easily add credit and debit card as payment options to your mobile application.

Compatibility

iOS 12.0 or later

Integration

via CocoaPods

If you use CocoaPods, then add these lines to your podfile:

pod 'PayMayaSDK'
via Swift Package Manager
.package(url: "https://github.com/PayMaya/PayMaya-iOS-SDK-v2.git")

Initialization

Initialize the SDK by specifying intended environment either sandbox or production, an optional level of console logging (off by default) and your API key for a specific payment method you want to use (it can be more than one). We recommend you to do this in your app delegate's didFinishLaunchingWithOptions: method

import PayMayaSDK

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
	...
	PayMayaSDK.setup(environment: .sandbox, logLevel: .all, [
        .checkout: "pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah",
        .payments: "pk-MOfNKu3FmHMVHtjyjG7vhr7vFevRkWxmxYL1Yq6iFk5",
        .cardToken: "pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah"
    ])
}

Using Checkout

  1. Create a CheckoutInfo object with total amount, items, redirection urls, an optional buyer information and optional request reference number (by default it will be auto-generated).
let itemsToBuy = [
    CheckoutItem(name: "Shoes",
                 quantity: 1,
                 totalAmount: CheckoutItemAmount(value: 99)),
    CheckoutItem(name: "Pants",
                 quantity: 1,
                 totalAmount: CheckoutItemAmount(value: 79)),
]

let totalAmount = CheckoutTotalAmount(value: itemsToBuy.map { $0.totalAmount.value }.reduce(0, +), currency: "PHP", details: AmountDetails(shippingFee:150))

let redirectUrl = RedirectURL(success: "https://www.merchantsite.com/success", 
                              failure: "https://www.merchantsite.com/failure", 
                              cancel: "https://www.merchantsite.com/cancel")!
                              
let checkoutInfo = CheckoutInfo(totalAmount: totalAmount, items: itemsToBuy, redirectUrl: redirectUrl, requestReferenceNumber: "1551191039")
  1. Call PayMayaSDK.presentCheckout method passing the controller on which the checkout process will present itself and the CheckoutInfo object with the transaction details. NOTE: The callback will be called first when id is created and second time once the process is finished, error occured or the user dismisses the controller.
import PayMayaSDK

class SomeViewController: UIViewController {
...
    func buyButtonTapped() {
        PayMayaSDK.presentCheckout(from: self, checkoutInfo: checkoutInfo) { result in
            switch result {
            
            // Called once the checkout id is created
            case .prepared(let checkoutId):
                
            // Called once the transaction is finished
            case .processed(let status):
            
                // The transaction status with your redirection url provided in the CheckoutInfo object
                switch status {
                case .success(let url):
                    
                case .failure(let url):
                    
                case .cancel(let url):
                    
                }
                
            // Called when user dismisses the checkout controller, passes the last known status.
            case .interrupted(let status):
            
            // For error handling
            case .error(let error):
            }
        }

    }
...
}
  • (if needed) Checking status for a checkout id
import PayMayaSDK

func getStatus() {
    PayMayaSDK.getCheckoutStatus(id: "someCheckoutId") { result in
        switch result {
        
        // Status for that checkout id
        case .success(let status):
            
        // For error handling
        case .failure(let error):
            
        }
    }
}

Using Pay with PayMaya

Single Payment

  1. Create a SinglePaymentInfo object with total amount, redirection urls and an optional request reference number (by default it will be auto-generated).
let redirectUrl = RedirectURL(success: "https://www.merchantsite.com/success",
                              failure: "https://www.merchantsite.com/failure",
                              cancel: "https://www.merchantsite.com/cancel")!
                              
let totalAmount = SinglePaymentTotalAmount(currency: "PHP", value: 199)

let singlePaymentInfo = SinglePaymentInfo(totalAmount: totalAmount, redirectUrl: redirectUrl, requestReferenceNumber: "6319921")
  1. Call PayMayaSDK.presentSinglePayment method passing the controller on which the payment process will present itself and the SinglePaymentInfo object with the transaction details. NOTE: The callback will be called first when id is created and second time once the process is finished, error occured or the user dismisses the controller.
import PayMayaSDK

class SomeViewController: UIViewController {
...
    func payButtonTapped() {
        PayMayaSDK.presentSinglePayment(from: self, singlePaymentInfo: singlePaymentInfo) { result in
            switch result {
            
            // Called once the payment id is created
            case .prepared(let paymentId):
                
            // Called once the transaction is finished
            case .processed(let status):
            
                // The transaction status with your redirection url provided in the SinglePaymentInfo object
                switch status {
                case .success(let url):
                    
                case .failure(let url):
                    
                case .cancel(let url):
                    
                }
                
            // Called when user dismisses the payment controller, passes the last known status.
            case .interrupted(let status):
            
            // For error handling
            case .error(let error):
            }
        }

    }
...
}
  • (if needed) Checking status for a payment id
import PayMayaSDK

func getStatus() {
    PayMayaSDK.getPaymentStatus(id: "somePaymentId") { result in
        switch result {
        
        // Status for that payment id
        case .success(let status):
            
        // For error handling
        case .failure(let error):
            
        }
    }
}

Creating a Wallet Link

  1. Create a WalletLinkInfo object with redirection urls and an optional request reference number (by default it will be auto-generated).
let redirectUrl = RedirectURL(success: "https://www.merchantsite.com/success",
                              failure: "https://www.merchantsite.com/failure",
                              cancel: "https://www.merchantsite.com/cancel")!
                              
let walletLinkInfo = WalletLinkInfo(redirectUrl: redirectUrl, requestReferenceNumber: "123456")
  1. Call PayMayaSDK.presentCreateWalletLink method passing the controller on which the wallet link creation process will present itself and the WalletLinkInfo object. NOTE: The callback will be called first when id is created and second time once the process is finished, error occured or the user dismisses the controller.
import PayMayaSDK

class SomeViewController: UIViewController {
...
    func createWalletButtonTapped() {
        PayMayaSDK.presentCreateWalletLink(from: self, walletLinkInfo: walletLinkInfo) { result in
            switch result {
            
            // Called once the wallet link id is created
            case .prepared(let walletId):
                
            // Called once the wallet link is created
            case .processed(let status):
            
                // The transaction status with your redirection url provided in the WalletLinkInfo object
                switch status {
                case .success(let url):
                    
                case .failure(let url):
                    
                case .cancel(let url):
                    
                }
                
            // Called when user dismisses the controller.
            case .interrupted:
            
            // For error handling
            case .error(let error):
            }
        }

    }
...
}

Using Payment Vault

Payment Vault provides merchants the ability to store their customer's card details and charge for payments on-demand

Create Payment Token

Call PayMayaSDK.presentCardPayment method passing the controller on which the card payment process will present itself.

import PayMayaSDK

class SomeViewController: UIViewController {
...
    func payButtonTapped() {
        PayMayaSDK.presentCardPayment(from: self) { result in

            switch result {
            
            // Called once the payment token is created
            case .success(let token):
                
            // For error handling
            case .error(let error):
            
            }
        }
    }
...
}

Optional styling

Call the method and choose between .dark / .light with your custom font, logo and the Pay Now button styling. All parameters are optional, so you can change only the ones you want.

let tintColor = UIColor.green
let font = UIFont.systemFont(ofSize: 18)
let logo = UIImage(named: "myLogo")
let buttonStyling = PayButtonStyling(title: "Pay with card", backgroundColor: .blue, textColor: .white)

PayMayaSDK.presentCardPayment(from: self, styling: .dark(buttonStyling: buttonStyling, font: font, logo: logo)) { result in
    ...
}

paymaya-ios-sdk-v2's People

Contributors

barayantan avatar cefjoeii avatar jorrelang avatar maciejgorecki avatar mannysoft avatar mbalawajder avatar rjarce avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

paymaya-ios-sdk-v2's Issues

optional styling for leftBarButtonItem

i would like to change tintColor of leftBarButtonItem, but tintColor variable of the documentation optional styling is never used

its so be nice if we can make custom styling for leftBarButtonItem like PayButtonStyling

XCTest embedded within Pod leads to crashes when importing the library

When loading Pod PayMayaSDK 2.0.0, applications may encounter the following crash:

dyld: Library not loaded: @rpath/XCTest.framework/XCTest
  Referenced from: /Users/ralph.arce/Library/Developer/CoreSimulator/Devices/3D9CF90B-E8AE-4AEA-A363-19162BE23659/data/Containers/Bundle/Application/D6D76726-FB47-4FD2-B572-9E770A12ACFD/PayMayaExample.app/PayMayaExample
  Reason: image not found

XCTest is baked in and embedded in the Podfile of PayMayaSDK, which is typically not present in actual environments and most simulator environments.

Cocoapods lint warnings

    - WARN  | xcodebuild:  PayMayaSDK/PayMayaSDK/PayMayaSDK/Views/CardPaymentTokenView.swift:27:40: warning: using 'class' keyword to define a class-constrained protocol is deprecated; use 'AnyObject' instead
    - WARN  | xcodebuild:  PayMayaSDK/PayMayaSDK/PayMayaSDK/Views/TextFields/LabeledTextField.swift:23:36: warning: using 'class' keyword to define a class-constrained protocol is deprecated; use 'AnyObject' instead
    - WARN  | xcodebuild:  PayMayaSDK/PayMayaSDK/PayMayaSDK/Extensions/String+Grouping.swift:23:43: warning: 'IndexDistance' is deprecated: All index distances are now of type Int
    - WARN  | xcodebuild:  PayMayaSDK/PayMayaSDK/PayMayaSDK/Networking/Extensions/URLSession+Networking.swift:22:1: warning: sendability of function types in instance method 'dataTask(with:completionHandler:)' does not match requirement in protocol 'FoundationNetworking'

Unable to confirm single payment on smaller screens

This is an issue with the html and css and not specifically this SDK. Using single payment method, the "Confirm Payment" button element is blocked on smaller screens.

Test done using iPhone SE Simulator on iOS version 13.2.2.
iPhone SE Screenshot:
Simulator Screen Shot - iPhone SE - 2020-10-20 at 19 35 25

iPhone 6 Screenshot:
Simulator Screen Shot - iPhone 6 - 2020-10-20 at 19 39 43

Not able to add dependency through SPM

Im using Xcode 12. Got this error when adding thru Swift Package manager

because every version of PayMaya-iOS-SDK-v2 contains incompatible tools version and root depends on PayMaya-iOS-SDK-v2 2.0.1..<3.0.0, version solving failed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.