Coder Social home page Coder Social logo

lushdigital / adyencheckout-ios Goto Github PK

View Code? Open in Web Editor NEW

This project forked from akoziol-solstice/adyencheckout-ios

0.0 3.0 0.0 335 KB

Adyen Checkout is a native client for accepting payments in-app.

License: MIT License

Ruby 0.98% Swift 57.21% Objective-C 21.06% Shell 15.68% JavaScript 4.93% HTML 0.13%

adyencheckout-ios's Introduction

AdyenCheckout

CI Status Version

Usage

To run the example project, clone the repo and run pod install from the example directory. You can use the library in two ways:

  • Plug & Play
  • Advanced.

Plug & Play example

Provide the token or public key to the library:

Checkout.shared.publicKey = "YOUR_ADYEN_PUBLIC_KEY"
// OR
Checkout.shared.token = "YOUR_ADYEN_TOKEN"

Show the CheckoutCardViewController to checkout with card:

// Create payment request
let request = CheckoutRequest()
request.amount = 1.99
request.currency = "EUR"
request.reference = "Merchant Reference 123"

// Create Checkout view controller
let vc = CheckoutCardViewController(checkoutRequest: request)
vc.delegate = self
vc.titleText = "My Company"

// Present the controller
let nc = UINavigationController(rootViewController: vc)
self.presentViewController(nc, animated: true, completion: nil)

And implement the CheckoutViewControllerDelegate functions:

func checkoutViewController(controller: CheckoutViewController, authorizedPayment payment: CheckoutPayment) {
    // Dismiss the view controller
    controller.dismissViewControllerAnimated(true, completion: nil)

    // Send the payment to your server which should validate it with Adyen
    sendPayment(payment) { (psp, error) -> Void in
        if (error != nil) {
            let alert = UIAlertView(title: "Error", message: error!.localizedDescription, delegate: nil, cancelButtonTitle: "OK")
            alert.show()
        } else {
            let alert = UIAlertView(title: "Success!", message: "PSP: \(psp)", delegate: nil, cancelButtonTitle: "OK")
            alert.show()
        }
    }
}

func checkoutViewController(controller: CheckoutViewController, failedWithError error: NSError) {
    // Dismiss the view controller
    controller.dismissViewControllerAnimated(true, completion: nil)

    //Show error
    let alert = UIAlertView(title: "Error", message: error.localizedDescription, delegate: nil, cancelButtonTitle: "OK")
    alert.show()
}

The CheckoutPayment contains amount, currency, reference and paymentData which is Base64 encrypted data.

More advanced Usage

Take power with the advance library usage. Display the card fields in your view by adding a separate CardPaymentField , UIView class.

let paymentFieldView = CardPaymentField()
self.view.addSubview(paymentFieldView)

Ensure that you have a valid public key for encryption, or get it with token:

if (Checkout.shared.publicKey == nil) {
    Checkout.shared.fetchPublickKey({ (publicKey, error) -> Void in
        if (error != nil) {
            // Handle error                    
        }
    })
}

Encrypt the obtained data:

if (paymentFieldView.valid) {
    let card = paymentFieldView.paymentData()
    do {
        let paymentData = try card.serialize()
        let payment = CheckoutPayment(request: self.request, encryptedData: paymentData)
        // Send payment to Adyen
    }
    catch let error as NSError {
        // Handle error
    }
}

Installation

AdyenCheckout is available through CocoaPods. To install add the following line to your Podfile:

pod "AdyenCheckout"

Checkout flow

CSE Checkout flow

License

AdyenCheckout is available under the MIT license. See the LICENSE file for more info.

adyencheckout-ios's People

Watchers

 avatar  avatar  avatar

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.