On Xamarin Forms, I am trying to send an Apple Pay payload to WorldPay (payment gateway). It has a guide on what the request should look like, and here is a short snippet:
<APPLEPAY-SSL>
<header>
<ephemeralPublicKey>AAAA...</ephemeralPublicKey>
<publicKeyHash>AAAA...</publicKeyHash>
<transactionId>AAAA...</transactionId>
</header>
<signature>AAAA...</signature>
<version>EC_v1</version>
<data>AAAA...</data>
</APPLEPAY-SSL>
I need to extract this mandatory data from the PKPayment object that I get in the below override
public override void DidAuthorizePayment(PKPaymentAuthorizationViewController controller, PKPayment payment, Action<PKPaymentAuthorizationStatus> completion)
{
completion(obj: PKPaymentAuthorizationStatus.Success);
}
The only examples I found on how to handle this object, are to use a 3rd party SDK (stripe) which extracts just the ID and Token, and not all that I need.
My current code is identical to the question here.
Please let me know how can I get the data world pay requires using apple pay in Xamarin.Forms.
Finally figured it out.
Step 1: Do not use an emulator! Emulators do not have a payload!
Step 2: Payload is inside PKPayment.Token.PaymentData
Step 3: Convert it to string: PaymentData.ToString()
End Result: string payload = payment.Token.PaymentData.ToString();
Result will be in JSON format and will contain everything that is required in the question.