2018-09-25 20:29:32 +02:00
import { Injectable } from '@angular/core' ;
2021-09-27 17:07:03 +02:00
import { Cordova , IonicNativePlugin , Plugin } from '@awesome-cordova-plugins/core' ;
2018-09-25 20:29:32 +02:00
export interface EncryptedCardData {
activationData : string ;
encryptedPassData : string ;
wrappedKey : string ;
}
2019-02-20 18:42:41 +02:00
export interface SignatureCertificatesData {
certificateSubCA : string ;
certificateLeaf : string ;
nonce : string ;
nonceSignature : string ;
}
2018-09-25 20:29:32 +02:00
export interface CardData {
cardholderName : string ;
primaryAccountNumberSuffix : string ;
localizedDescription? : string ;
2019-02-20 18:42:41 +02:00
paymentNetwork? : string ;
}
2019-06-10 20:00:44 +02:00
export interface PairedDevicesFlags {
2019-02-20 18:42:41 +02:00
isInWallet : boolean ;
isInWatch : boolean ;
FPANID : string ;
}
export interface WatchExistData {
isWatchPaired : boolean ;
}
2018-09-25 20:29:32 +02:00
/ * *
* @name Apple Wallet
* @description
* A Cordova plugin that enables users from Add Payment Cards to their Apple Wallet .
*
* @usage
* ` ` ` typescript
2021-09-27 17:07:03 +02:00
* import { AppleWallet } from '@awesome-cordova-plugins/apple-wallet/ngx' ;
2018-09-25 20:29:32 +02:00
*
*
* constructor ( private appleWallet : AppleWallet ) { }
*
2019-02-20 18:42:41 +02:00
*
2018-09-25 20:29:32 +02:00
* . . .
*
*
2019-02-20 18:42:41 +02:00
* // Simple call to determine if the current device supports Apple Pay and has a supported card installed.
* this . appleWallet . isAvailable ( )
* . then ( ( res : boolean ) = > {
* // Expect res to be boolean
2018-09-25 20:29:32 +02:00
* } )
2019-02-20 18:42:41 +02:00
* . catch ( ( err ) = > {
* // Catch {{err}} here
2018-09-25 20:29:32 +02:00
* } ) ;
*
* . . .
*
2019-02-20 18:42:41 +02:00
*
2019-06-10 20:00:44 +02:00
* // Simple call to check Card Eligibility
* this . appleWallet . checkCardEligibility ( primaryAccountIdentifier : string )
* . then ( ( res : boolean ) = > {
* // Expect res to be boolean
2019-02-20 18:42:41 +02:00
* } )
* . catch ( ( err ) = > {
* // Catch {{err}} here
* } ) ;
*
*
* . . .
*
*
2019-06-10 20:00:44 +02:00
* // Simple call to checkCardEligibilityBySuffix
* this . appleWallet . checkCardEligibilityBySuffix ( cardSuffix : string )
* . then ( ( res : boolean ) = > {
* // Expect res to be boolean
* } )
* . catch ( ( err ) = > {
* // Catch {{err}} here
* } ) ;
*
*
* . . .
*
2019-02-20 18:42:41 +02:00
* // Simple call to check out if there is any paired Watches so that you can toggle visibility of 'Add to Watch' button
2019-06-10 20:00:44 +02:00
* this . appleWallet . checkPairedDevices ( )
2019-02-20 18:42:41 +02:00
* . then ( ( res : WatchExistData ) = > {
2019-06-10 20:00:44 +02:00
* // object contains boolean flags showing paired devices
* } )
* . catch ( ( err ) = > {
* // Catch {{err}} here
* } ) ;
*
*
* . . .
*
*
*
* // Simple call to check paired devices with a card by its suffix
* this . appleWallet . checkPairedDevicesBySuffix ( cardSuffix : string )
* . then ( ( res : PairedDevicesFlags ) = > {
* // object contains boolean values that ensure that card is already exists in wallet or paired-watch
2019-02-20 18:42:41 +02:00
* } )
* . catch ( ( err ) = > {
* // Catch {{err}} here
* } ) ;
*
*
* . . .
*
*
* // 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
2018-09-25 20:29:32 +02:00
*
* this . appleWallet . startAddPaymentPass ( data : cardData )
2019-02-20 18:42:41 +02:00
* . then ( ( res : SignatureCertificatesData ) = > {
* // User proceed and successfully asked to add card to his wallet
* // Use the callback response JSON payload to complete addition process
2018-09-25 20:29:32 +02:00
* } )
* . catch ( ( err ) = > {
2019-02-20 18:42:41 +02:00
* // Catch {{err}} here
2018-09-25 20:29:32 +02:00
* } ) ;
*
2019-02-20 18:42:41 +02:00
*
2018-09-25 20:29:32 +02:00
* . . .
*
*
2019-02-20 18:42:41 +02:00
* this . appleWallet . completeAddPaymentPass ( data : encryptedCardData )
* . then ( ( res : string ) = > {
* // Expect res to be string either 'success' or 'error'
2018-09-25 20:29:32 +02:00
* } )
* . catch ( ( err ) = > {
2019-02-20 18:42:41 +02:00
* // Catch {{err}} here
* // Error and can not add the card, or something wrong happend
* // PKAddPaymentPassViewController will be dismissed
2018-09-25 20:29:32 +02:00
* } ) ;
*
* ` ` `
* @Interfaces
* EncryptedCardData
2019-02-20 18:42:41 +02:00
* SignatureCertificatesData
2018-09-25 20:29:32 +02:00
* CardData
2019-06-10 20:00:44 +02:00
* PairedDevicesFlags
2019-02-20 18:42:41 +02:00
* WatchExistData
2018-09-25 20:29:32 +02:00
* /
@Plugin ( {
pluginName : 'AppleWallet' ,
plugin : 'cordova-apple-wallet' ,
pluginRef : 'AppleWallet' ,
repo : 'https://github.com/tomavic/cordova-apple-wallet' ,
2020-05-16 14:40:49 +02:00
platforms : [ 'iOS' ] ,
2018-09-25 20:29:32 +02:00
} )
2019-02-20 17:37:39 +01:00
@Injectable ( )
2018-09-25 20:29:32 +02:00
export class AppleWallet extends IonicNativePlugin {
/ * *
2019-02-20 18:42:41 +02:00
* Simple call to determine if the current device supports Apple Pay and has a supported card installed .
* @return { Promise < boolean > }
* /
@Cordova ( )
isAvailable ( ) : Promise < boolean > {
return ;
}
/ * *
2019-06-10 20:00:44 +02:00
* Simple call to check Card Eligibility
* @param { string } primaryAccountIdentifier
* @return { Promise < boolean > }
* /
@Cordova ( )
checkCardEligibility ( primaryAccountIdentifier : string ) : Promise < boolean > {
return ;
}
/ * *
* Simple call to checkCardEligibilityBySuffix
* @param { string } cardSuffix
* @return { Promise < PairedDevicesFlags > }
2019-02-20 18:42:41 +02:00
* /
@Cordova ( )
2019-06-10 20:00:44 +02:00
checkCardEligibilityBySuffix ( cardSuffix : string ) : Promise < boolean > {
2019-02-20 18:42:41 +02:00
return ;
}
/ * *
* Simple call to check out if there is any paired Watches so that you can toggle visibility of 'Add to Watch' button
* @return { Promise < WatchExistData > }
2018-09-25 20:29:32 +02:00
* /
@Cordova ( )
2019-06-10 20:00:44 +02:00
checkPairedDevices ( ) : Promise < WatchExistData > {
return ;
}
/ * *
* Simple call to check paired devices with a card by its suffix
* @param { string } cardSuffix
* @return { Promise < PairedDevicesFlags > }
* /
@Cordova ( )
checkPairedDevicesBySuffix ( cardSuffix : string ) : Promise < PairedDevicesFlags > {
2018-09-25 20:29:32 +02:00
return ;
}
/ * *
* Simple call with the configuration data needed to instantiate a new PKAddPaymentPassViewController object .
* @param { cardData } data
2019-02-20 18:42:41 +02:00
* @return { Promise < SignatureCertificatesData > }
2018-09-25 20:29:32 +02:00
* /
@Cordova ( )
2019-02-20 18:42:41 +02:00
startAddPaymentPass ( data : CardData ) : Promise < SignatureCertificatesData > {
2018-09-25 20:29:32 +02:00
return ;
}
/ * *
2019-02-20 18:42:41 +02:00
* 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 .
2018-09-25 20:29:32 +02:00
* @param { encryptedCardData } data
2019-02-20 18:42:41 +02:00
* @return { Promise < string > }
2018-09-25 20:29:32 +02:00
* /
@Cordova ( )
2019-02-20 18:42:41 +02:00
completeAddPaymentPass ( data : EncryptedCardData ) : Promise < string > {
2018-09-25 20:29:32 +02:00
return ;
}
}