Check what you need
Three things have to be true before a card reaches a phone:
Always call Agentcard from your server, with your company access token. Your app never holds that token: it asks your server, and your server asks Agentcard.
Add a card to Apple Pay
Show Apple’s “Add to Apple Wallet” button only when the phone can add cards and this card is not in Wallet yet. When your user taps it, open Apple’s add-card screen (PKAddPaymentPassViewController) with the card’s last four digits and the cardholder’s name.
Apple then hands your app three values: a list of certificates, a nonce and a nonce signature. Encode each one in base64, send them to your server, and have your server ask Agentcard right away, because the nonce expires within a few minutes:
device_id is an id your app keeps for the phone the card goes to. Pass the three answer fields back to your app, decode them from base64, and give them to Apple in a PKAddPaymentPassRequest. Apple shows your user its terms, adds the card, and tells your app when the card is in Wallet.
If your server cannot get the data, give Apple an empty request. Apple then tells your user the card could not be added, and your user can try again.
Add a card to Google Pay
Show Google’s “Add to Google Pay” button only when the card is not in your user’s Google Wallet yet. Send an id your app keeps for the phone to your server, and have your server ask Agentcard:opaque_payment_card decoded from base64, the network and token service set to Visa, and last4, then call pushTokenize. Google shows your user its terms and adds the card.