-
Notifications
You must be signed in to change notification settings - Fork 31
/
decode_token.php
42 lines (31 loc) · 5.25 KB
/
decode_token.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
use PayU\ApplePay\ApplePayDecodingServiceFactory;
use PayU\ApplePay\ApplePayValidator;
use PayU\ApplePay\Exception\DecodingFailedException;
use PayU\ApplePay\Exception\InvalidFormatException;
require __DIR__ . '/../vendor/autoload.php';
// private key used to create the CSR
$privateKey = 'MHcCAQEEIEV17KjFHD0W014fRRnbM4Un9gkOEYhJz/A/qWPd9PIloAoGCCqGSM49AwEHoUQDQgAESRBiGT+GnbM3r1M4fhYEFUKe6EHA+z6r2ctjtWqeAs9wI48MBoGKFrwWqY/zbzMNYgaOm+DnUMjF8v8v1nMtag==';
// merchant identifier from Apple Pay Merchant Account
$appleId = 'merchant.sandbox.payu';
// payment token data received from Apple Pay
$paymentData = '{"version":"EC_v1","data":"UeSmPQQawN6olhB0LNY1cZZ000mToaFGdkMN6OxU9lAAPa9IWPDN9tISOknANVSdkVXi51y2kCqaimjFFuOWFxLNngiZtHdPHLNuz8tgLLVKnvd6mxc40Iz9sQmg93K4BNHGSxC69BGz5QrcrXP3BE96aWtuty3Kuzz+PCiHvEfhMwnW\/EpERJdQrJrDmzUwydRhKNS9Cu1ohLHeQo0ngKjbFon0Io5133h1jYhDsYBnL4vOeNDMFKKH+Rv6nG+U4dsBG1DNXFitMywWVBfGcPWtgEMUQcIJnVP61TTMhQl6dHe13QaWOdW+YYKBMZuBvyUKH+7WuFWZWAEn8m4+Ase0rglxpX14tiprGagjqxRm7QH4zQK4lrVy5JD2DQ26fAUtlvlGxBJz2TAht0FU","signature":"MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCAMIID5jCCA4ugAwIBAgIIaGD2mdnMpw8wCgYIKoZIzj0EAwIwejEuMC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BgoqhkiG92NkBgIOBAIFADAKBggqhkjOPQQDAgNnADBkAjA6z3KDURaZsYb7NcNWymK\/9Bft2Q91TaKOvvGcgV5Ct4n4mPebWZ+Y1UENj53pwv4CMDIt1UQhsKMFd2xd8zg7kGf9F3wsIW2WT8ZyaYISb1T4en0bmcubCYkhYQaZDwmSHQAAMYIBjTCCAYkCAQEwgYYwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTAghoYPaZ2cynDzANBglghkgBZQMEAgEFAKCBlTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0xODAxMjYxMzU1MThaMCoGCSqGSIb3DQEJNDEdMBswDQYJYIZIAWUDBAIBBQChCgYIKoZIzj0EAwIwLwYJKoZIhvcNAQkEMSIEIE3cv23pCPQcC4NYY9JgJPyF\/Xmrxnm+lwHQqfvM6Sb1MAoGCCqGSM49BAMCBEgwRgIhAO2PZavNEzOYVVlfnnd+FK+YFMAY+KFAX0x2zYMS9M3IAiEA5rEdGSq\/ljS\/xvLye9zJtSmtzoDuNAjdaDtbjZ21ozAAAAAAAAA=","header":{"ephemeralPublicKey":"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE8VfEh4f\/PF4eTCblWerBJCgpg1BrhZZbpIroEfw\/7OZkkVyAlneu5SIBZXbrQRTrHOfh16Lue4t0y99brvzGFA==","publicKeyHash":"zZPAYNrLOwPbRsav95FZTIYlKF6dULquEHppV6TRPmc=","transactionId":"07e1cfeea3952ca4fcc87d080cf47feb3c3ab2e8fe7261db26457fb361e9d02e"}}';
// how many seconds should the token be valid since the creation time.
$expirationTime = 315360000; // It should be changed in production to a reasonable value (a couple of minutes)
$rootCertificatePath = __DIR__ . '/AppleRootCA-G3.pem';
$applePayDecodingServiceFactory = new ApplePayDecodingServiceFactory();
$applePayDecodingService = $applePayDecodingServiceFactory->make();
$applePayValidator = new ApplePayValidator();
$paymentData = json_decode($paymentData, true);
try {
$applePayValidator->validatePaymentDataStructure($paymentData);
$decodedToken = $applePayDecodingService->decode($privateKey, $appleId, $paymentData, $rootCertificatePath, $expirationTime);
echo 'Decoded token is: '.PHP_EOL.PHP_EOL;
var_dump($decodedToken);
} catch(DecodingFailedException $exception) {
echo 'Decoding failed: '.PHP_EOL.PHP_EOL;
echo $exception->getMessage();
} catch(InvalidFormatException $exception) {
echo 'Invalid format: '.PHP_EOL.PHP_EOL;
echo $exception->getMessage();
}