Giter Site home page Giter Site logo

os-adv-dev / cordova-apple-wallet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andregrillo/cordova-apple-wallet

0.0 0.0 0.0 121 KB

A Cordova plugin that provides easy use for adding your credit/debit cards to Apple Wallet. It also can check if the credit/debit card exists in Wallet or any paired device e.g. Apple Watch

JavaScript 28.28% Objective-C 71.72%

cordova-apple-wallet's Introduction

alt text

cordova-apple-wallet

This plugin provides support for adding your credit/debit cards to Apple Wallet. It also can check if the credit/debit card exists in Wallet or any paired device e.g. Apple Watch ⌚

πŸ‘‰ Important Note

Adding payment passes requires a special entitlement issued by Apple. Your app must include this entitlement before you can use this class. For more information on requesting this entitlement, see the Card Issuers section at developer.apple.com/apple-pay/.

Installation

Ionic 3 and above

In order to use it with Ionic 3, please follow this instructions

Phonegap

cordova plugin add cordova-apple-wallet --save

Or the latest (unstable) version:

  cordova plugin add --save https://github.com/tomavic/cordova-apple-wallet

πŸ‘‰ NOTE: In order to use it with normal cordova based project, please define a global variable, so that you can use it without lint errors var AppleWallet = AppleWallet || {};

How to use

βœ”οΈ Availability

Simple call to determine if the current device supports Apple Pay and has a supported card installed.

    AppleWallet.isAvailable()
    .then((res) => {
    /**
     * Expect res to be boolean
     */
    })
    .catch((err) => {
      // Catch {{err}} here
    });

βœ”οΈ Eligibility

Simple call to check existence and eligibility to add a card

    let data = {
      primaryAccountSuffix: '1234'
    }
    AppleWallet.isCardExistInWalletOrWatch(data)
    .then((res) => {
    /**
     * object contains boolean values that ensure that card is already exists in wallet or paired-watch
     * Expect
     * res = {
     *    isInWallet: boolean
     *    isInWatch: boolean
     *    FPANID: string
     * }
     * */
    })
    .catch((err) => {
      // Catch {{err}} here
    });

βœ”οΈ Apple Watch Existence

Simple call to check out if there is any paired Watches so that you can toggle visibility of 'Add to Watch' button

    AppleWallet.isPairedWatchExist()
    .then((res) => {
    /**
     * Expect
     * res = {
     *   isWatchPaired: boolean
     * }
     */
    })
    .catch((err) => {
      // Catch {{err}} here
    });

βœ”οΈ Card Addition

Simple call with the configuration data needed to instantiate a new PKAddPaymentPassViewController object.

This method provides the data needed to create a request to add your payment pass (credit/debit card). After a successful callback, pass the certificate chain to your issuer server-side using our callback delegate method AppleWallet.completeAddPaymentPass. The issuer server-side should returns an encrypted JSON payload containing the encrypted card data, which is required to be get the final response

    let data = {
      cardholderName: 'Test User',
      primaryAccountNumberSuffix: '1234',
      localizedDescription: 'Description of payment card',
      paymentNetwork: 'VISA'
    }
    AppleWallet.startAddPaymentPass(data)
    .then((res) => {
    /**
     * User proceed and successfully asked to add card to his wallet
     * Use the callback response JSON payload to complete addition process
     * Expect
     * res = {
     *   "certificateSubCA":"Base64 string represents certificateSubCA",
     *   "certificateLeaf":"Base64 string represents certificateLeaf"
     *   "nonce":"Base64 string represents nonce",
     *   "nonceSignature":"Base64 string represents nonceSignature",
     * }
     */
    })
    .catch((err) => {
      // Error or user cancelled.
    });

πŸ‘‰ NOTE: The encryption scheme, cardholder name, and primary account suffix are required for configuration. The configuration information is used for setup and display only. It should not contain any sensitive information.

In order to get testing data check this Apple Sandbox


βœ”οΈ Card Addition Callback Delegate

Simple completion handler that takes encrypted card data returned from your server side, in order to get the final response from Apple to know if the card is added succesfully or not.

  • activationData: The request’s activation data.
  • encryptedPassData : An encrypted JSON file containing the sensitive information needed to add a card to Apple Pay.
  • ephemeralPublicKey The ephemeral public key used by elliptic curve cryptography (ECC). or wrappedKey if you are using RSA
    let encryptedData = {
        activationData: "encoded Base64 activationData from your server",
        encryptedPassData: "encoded Base64 encryptedPassData from your server",
        wrappedKey: "encoded Base64 wrappedKey from your server"
    }
    AppleWallet.completeAddPaymentPass(encryptedData)
    .then((res) => {
      /**
       * A success callback response means card has been added successfully,
       * PKAddPaymentPassViewController will be dismissed
       * Expect
       * res to be String value 'success' or 'error'
       */
    })
    .catch((err) => {
      // Error and can not add the card, or something wrong happend
      // PKAddPaymentPassViewController will be dismissed
    });

Support

For more information, please check Apple Developer documentation from here

Contribute

Please support us by giving advice on how to apply best practice and code review.

License

MIT

Credits

Made with ❀️ by Hatem. Follow me on Twitter to get the latest news first! I will be happy to receive your feedback via Email ! I am always happy to hear your feedback. Enjoy!

β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„β–„ 
β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–€β–ˆβ–„β–€β–„β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–€β–ˆβ–„β–€β–„β–€β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 
β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–€β–ˆβ–„β–ˆβ–„β–ˆβ–ˆβ–ˆβ–€β–‘β–‘β–‘β–‘β–‘β–‘β–€β–ˆβ–„β–ˆβ–„β–ˆβ–ˆβ–ˆβ–€β–‘

All copyrights reserved Β© 2019 | Enigma Labs Ltd | Tomas

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.