Alipay+ DocsAlipay+ Docs

generateAddPaymentPassRequestForPassEntryWithIdentifier

Call the generateAddPaymentPassRequestForPassEntryWithIdentifier API to create an object with the data Apple needs to add a card to Apple Pay.

Method signature

copy
@available(iOS 14.0, *)
public static func generateAddPaymentPassRequestForPassEntryWithIdentifier(_ identifier: String,
                                                                           configuration: PKAddPaymentPassRequestConfiguration,
                                                                           certificates: [Data],
                                                                           nonce: Data,
                                                                           nonceSignature: Data,
                                                                           completion: @escaping (Result<PKAddPaymentPassRequest, IAPAPErrors>) -> Void)

Request parameters

Parameter

Type

Required

Description

identifier

String

Yes

The identifier to identity the card.

configuration

PKAddPaymentPassRequestConfiguration

Yes

The configuration used by the system to add a secure device token.

certificates

[Data]

Yes

An array of data objects. Each object contains a DER-encoded X.509 certificate, ordered from leaf to root. You must download the root CA to validate the entire chain.

nonce

Data

Yes

A one-time nonce value generated by Apple's servers. You must include this signature nonce in the add-payment request's encrypted data.

nonceSignature

Data

Yes

The device-specific signature for the nonce. This signature must be included in the add payment request's encrypted data.

completion

(Result<PKAddPaymentPassRequest, IAPAPErrors>) -> Void

Yes

An asynchronous completion callback that returns the result of calling the generateAddPaymentPassRequestForPassEntryWithIdentifier API.

PKAddPaymentPassRequestConfiguration

Parameter

Type

Required

Description

cardholderName

String?

No

The name of the person as shown on the card.

encryptionScheme

PKEncryptionScheme

Yes

The encryption scheme to be used in this request.

For valid values, see PKEncryptionScheme.

localizedDescription

String?

No

A short description of the card.

primaryAccountSuffix

String?

No

The last four or five digits of the card's number.

cardDetails

[PKLabeledValue]

Yes

An array of labeled values that describe a card.

productIdentifiers

Set<String>

Yes

A set of unique identifiers used to identify a product.

style

PKAddPaymentPassStyle

Yes

A value that indicates whether a device token is for access or for payment use.

Valid values are:

  • access: A device token that authorizes the user to access a location or resource.
  • payment: A device token used by a customer for purchasing.

PKLabeledValue

Parameter

Type

Required

Description

label

String

Yes

A string that contains the label for the value.

value

String

Yes

A string that contains the value associated with a label.

Response parameters

N/A

Sample

copy
class IssuerExtensionHandler: PKIssuerProvisioningExtensionHandler {

    // ...
    
    override func generateAddPaymentPassRequestForPassEntryWithIdentifier(_ identifier: String,
                                                                          configuration: PKAddPaymentPassRequestConfiguration,
                                                                          certificateChain certificates: [Data],
                                                                          nonce: Data,
                                                                          nonceSignature: Data,
                                                                          completionHandler completion: @escaping (PKAddPaymentPassRequest?) -> Void) {
        IAPApplePay.generateAddPaymentPassRequestForPassEntryWithIdentifier(identifier, configuration: configuration, certificates: certificates, nonce: nonce, nonceSignature: nonceSignature) { result in
            switch result {
            case .success(let request):
                // handle success and completion request
                completion(request)
            case .failure(let error):
                // handle error and completion nil
                completion(nil)
            }
        }
    }
}