Skip to main content
Version: 13.x (Current)

Apple Pay

Note that at the moment Apple Pay payments are only supported with the Gestpay (Axerve) provider.

Gestpay

Making a payment

The service is expecting a JSON representation of a ApplePayPKPaymentToken described as below:

{
paymentData: {
data: string,
signature: string,
version: string,
header: {
ephemeralPublicKey: string,
publicKeyHash: string,
transactionId: string,
}
},
transactionIdentifier: string
paymentMethod: {
network: string,
type: string,
displayName: string
}
}

How to retrieve the payment token

Few steps are required in order to obtain a payment dictionary compliant to the structure expected above. After making a PKPaymentRequest using Apple's PassKit framework, you can retrieve the PKPayment object from the PKPaymentAuthorizationViewController didAuthorizePayment completion callback.

  1. Create a Foundation object from the given payment.token.paymentData data:

    NSData *paymentData = payment.token.paymentData;
    NSError *serializationError = nil;

    id dict = [NSJSONSerialization JSONObjectWithData:paymentData options:NSJSONReadingFragmentsAllowed error:&serializationError];
    // error handling with serializationError
  2. Create the payment method dictionary:

    // ...
    NSDictionary *paymentMethodDictionary = @{
    @"network": payment.token.paymentMethod.network,
    @"type": [NSNumber numberWithUnsignedLongLong:payment.token.paymentMethod.type],
    @"displayName":payment.token.paymentMethod.displayName
    };
    // ...
  3. Create the payment information dictionary and convert it as JSON data:

    // ...
    NSError *dataWritingError = nil;
    NSDictionary *paymentDictionary = @{
    @"paymentData":dict,
    @"transactionIdentifier":payment.token.transactionIdentifier,
    @"paymentMethod":paymentMethodDictionary
    };

    NSData *data = [NSJSONSerialization dataWithJSONObject:paymentDictionary options:NSJSONWritingFragmentsAllowed error:&dataWritingError];
    // error handling with dataWritingError
  4. Initialize a NSString with the data to be used as token to be provided to the /pay endpoint:

    // ...
    NSString *paymentDataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    // ...