<?php use Jose\Component\Encryption\Algorithm\KeyEncryption\RSAOAEP256; use Jose\Component\Encryption\Algorithm\ContentEncryption\A256CBCHS512; use Jose\Component\Encryption\JWEBuilder; use Jose\Component\Encryption\Serializer\CompactSerializer; use Jose\Component\Core\JWK; // Load the PGW's Encryption Public Key $pgwEncryptionPublicKey = file_get_contents('key/PACOEncryptionPublic.txt'); // JSON Payload to be encrypted $payload = [ 'amount' => '100.00', 'currency' => 'USD', 'customer_id' => '12345', ]; // Create a JWK instance for key encryption $keyEncryptionKey = JWK::createFromKey($pgwEncryptionPublicKey, null, ['alg' => 'RSA-OAEP-256', 'use' => 'enc']); // Build the JWE token $jweBuilder = new JWEBuilder(); $jwe = $jweBuilder ->create() // Create an empty JWE token ->withPayload(json_encode($payload)) // Set the JSON payload ->withEncryptionKey($keyEncryptionKey) // Set the encryption key ->addRecipient($keyEncryptionKey) // Add recipient for key encryption ->withHeader('alg', 'RSA-OAEP-256') // Specify key encryption algorithm ->withHeader('enc', 'A256CBC-HS512') // Specify content encryption algorithm ->build(); // Build the JWE token // Serialize the JWE token $jweSerializer = new CompactSerializer(); $serializedJwe = $jweSerializer->serialize($jwe); // Attach the encrypted payload to your API request and send it to 2C2P Payment Gateway // ... ?>