|
| 1 | +import { Injectable } from '@angular/core'; |
| 2 | +import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; |
| 3 | + |
| 4 | +export interface EncryptedCardData { |
| 5 | + activationData: string; |
| 6 | + encryptedPassData: string; |
| 7 | + wrappedKey: string; |
| 8 | +} |
| 9 | + |
| 10 | +export interface CardData { |
| 11 | + cardholderName: string; |
| 12 | + primaryAccountNumberSuffix: string; |
| 13 | + localizedDescription?: string; |
| 14 | + paymentNetwork: string; |
| 15 | +} |
| 16 | + |
| 17 | +/** |
| 18 | + * @name Apple Wallet |
| 19 | + * @description |
| 20 | + * A Cordova plugin that enables users from Add Payment Cards to their Apple Wallet. |
| 21 | + * |
| 22 | + * @usage |
| 23 | + * ```typescript |
| 24 | + * import { AppleWallet } from '@ionic-native/apple-wallet'; |
| 25 | + * |
| 26 | + * |
| 27 | + * constructor(private appleWallet: AppleWallet) { } |
| 28 | + * |
| 29 | + * ... |
| 30 | + * |
| 31 | + * |
| 32 | + * this.appleWallet.available() |
| 33 | + * .then((res) => { |
| 34 | + * // res is a boolean value, either true or false |
| 35 | + * console.log("Is Apple Wallet available? ", res); |
| 36 | + * }) |
| 37 | + * .catch((message) => { |
| 38 | + * console.error("ERROR AVAILBLE>> ", message); |
| 39 | + * }); |
| 40 | + * |
| 41 | + * ... |
| 42 | + * |
| 43 | + * let data: cardData = { |
| 44 | + * cardholderName: 'Test User', |
| 45 | + * primaryAccountNumberSuffix: '1234', |
| 46 | + * localizedDescription: 'Description of payment card', |
| 47 | + * paymentNetwork: 'VISA' |
| 48 | + * } |
| 49 | + * |
| 50 | + * this.appleWallet.startAddPaymentPass(data: cardData) |
| 51 | + * .then((res) => { |
| 52 | + * console.log("startAddPaymentPass success response ", res); |
| 53 | + * }) |
| 54 | + * .catch((err) => { |
| 55 | + * console.error("startAddPaymentPass ERROR response", err); |
| 56 | + * }); |
| 57 | + * |
| 58 | + * ... |
| 59 | + * |
| 60 | + * let data: encryptedCardData = { |
| 61 | + * activationData: 'encoded Base64 activationData from your server', |
| 62 | + * encryptedPassData: 'encoded Base64 encryptedPassData from your server', |
| 63 | + * wrappedKey: 'encoded Base64 wrappedKey from your server', |
| 64 | + * } |
| 65 | + * |
| 66 | + * this.appleWallet.encryptedCardData(data: encryptedCardData) |
| 67 | + * .then((res) => { |
| 68 | + * console.log("completeAddCardToAppleWallet success response ", res); |
| 69 | + * }) |
| 70 | + * .catch((err) => { |
| 71 | + * console.error("completeAddCardToAppleWallet ERROR response", err); |
| 72 | + * }); |
| 73 | + * |
| 74 | + * ``` |
| 75 | + * @Interfaces |
| 76 | + * EncryptedCardData |
| 77 | + * CardData |
| 78 | + */ |
| 79 | +@Plugin({ |
| 80 | + pluginName: 'AppleWallet', |
| 81 | + plugin: 'cordova-apple-wallet', |
| 82 | + pluginRef: 'AppleWallet', |
| 83 | + repo: 'https://github.com/tomavic/cordova-apple-wallet', |
| 84 | + platforms: ['iOS'] |
| 85 | +}) |
| 86 | +@Injectable() |
| 87 | +export class AppleWallet extends IonicNativePlugin { |
| 88 | + /** |
| 89 | + * Detects if the current device supports Apple Wallet |
| 90 | + * @return {Promise<boolean>} Returns a promise |
| 91 | + */ |
| 92 | + @Cordova() |
| 93 | + available(): Promise<boolean> { |
| 94 | + return; |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * Simple call with the configuration data needed to instantiate a new PKAddPaymentPassViewController object. |
| 99 | + * @param {cardData} data |
| 100 | + * @return {Promise<any>} Returns a promise |
| 101 | + */ |
| 102 | + @Cordova() |
| 103 | + startAddPaymentPass(data: CardData): Promise<any> { |
| 104 | + return; |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * Simple call contains the card data needed to add a card to Apple Pay. |
| 109 | + * @param {encryptedCardData} data |
| 110 | + * @return {Promise<any>} Returns a promise |
| 111 | + */ |
| 112 | + @Cordova() |
| 113 | + completeAddPaymentPass(data: EncryptedCardData): Promise<any> { |
| 114 | + return; |
| 115 | + } |
| 116 | +} |
0 commit comments