<?php use Carbon\Carbon; use GuzzleHttp\Exception\GuzzleException; use Paco\PhpDemo\ActionRequest; use Paco\PhpDemo\SecurityData; class Payment extends ActionRequest { /** * @throws GuzzleException */ public function Execute(): string { $now = Carbon::now(); $orderNo = $now->getPreciseTimestamp(3); $request = [ "apiRequest" => [ "requestMessageID" => $this->Guid(), "requestDateTime" => $now->utc()->format('Y-m-d\TH:i:s.v\Z'), "language" => "en-US", ], "officeId" => "2206", "terminalId" => "3335", "orderNo" => $orderNo, "productDescription" => "desc for '$orderNo'", "paymentType" => "CC", //fix "paymentCategory" => "ECOM", //fix // "creditCardDetails" => [ // "cardNumber" => "4706860000002325", // "cardExpiryMMYY" => "1225", // "cvvCode" => "761", // "payerName" => "Demo Sample" // ], // "storeCardDetails" => [ // "storeCardFlag" => "N", // "storedCardUniqueID" => "{{guid}}" // ], "installmentPaymentDetails" => [ "ippFlag" => "N"// fix, //"installmentPeriod" => 0, //"interestType" => null ], "mcpFlag" => "N", // fix "request3dsFlag" => "N", // UAT ให้กำหนดเป็น N เมื่อขึ้น production ให้เปลี่ยน เป็น Y ===> คือส่วนที่ส่งหน้าให้ป้อน OTP "transactionAmount" => [ "amountText" => "000000000100", "currencyCode" => "THB", "decimalPlaces" => 2, "amount" => 1 ], "channelCode" => "WEBPAY",//fix "autoRedirectDelayTimer"=> 5, //ตามต้องการว่าจะให้กลับมาที่หน้า ม.ราม กี่นาที "notificationURLs" => [ "confirmationURL" => "http://example-confirmation.com", "failedURL" => "http://example-failed.com", "cancellationURL" => "http://example-cancellation.com", "backendURL" => "http://example-backend.com" ], "recurringPaymentDetails" => [ "rppFlag"=>"N" // fix ]//, // "deviceDetails" => [ // "browserIp" => "1.0.0.1", // "browser" => "Postman Browser", // "browserUserAgent" => "PostmanRuntime/7.26.8 - not from header", // "mobileDeviceFlag" => "N" // ], // "purchaseItems" => [ // [ // "purchaseItemType" => "ticket", // "referenceNo" => "2322460376026", // "purchaseItemDescription" => "Bundled insurance", // "purchaseItemPrice" => [ // "amountText" => "000000100000", // "currencyCode" => "THB", // "decimalPlaces" => 2, // "amount" => 1000 // ], // "subMerchantID" => "string", // "passengerSeqNo" => 1 // ] // ], // "customFieldList" => [ // [ // "fieldName" => "TestField", // "fieldValue" => "This is test" // ] // ] //ส่วน generalPayerDetails ธนาคาร แจ้งว่าไม่ต้องมีก็ได้ // "generalPayerDetails" => [ // "personType"=> "General", // "seqNo" => 1, // "personName"=> [ // "title"=> "Mr.", // "firstName"=> "Merchant Test Tool User" // ] // ], ]; $stringRequest = json_encode($request); //third-party http client https://github.com/guzzle/guzzle $response = $this->client->post('https://core.demo-paco.2c2p.com/api/1.0/Payment/prePaymentUi', [ 'headers' => [ 'Accept' => 'application/json', 'apiKey' => SecurityData::$AccessToken, //$AccessToken คือ api key 'Content-Type' => 'application/json; charset=utf-8' ], 'body' => $stringRequest ]); return $response->getBody()->getContents(); } /** * @throws GuzzleException * @throws Exception */ public function ExecuteJose(): string { $now = Carbon::now(); $orderNo = $now->getPreciseTimestamp(3); $request = [ "apiRequest" => [ "requestMessageID" => $this->Guid(), "requestDateTime" => $now->utc()->format('Y-m-d\TH:i:s.v\Z'), "language" => "en-US", ], "officeId" => "2206", "terminalId" => "3335", "orderNo" => $orderNo,//ref "productDescription" => "desc for '$orderNo'", "paymentType" => "CC", "paymentCategory" => "ECOM", // "creditCardDetails" => [ // "cardNumber" => "4706860000002325", // "cardExpiryMMYY" => "1225", // "cvvCode" => "761", // "payerName" => "Demo Sample" // ], // "storeCardDetails" => [ // "storeCardFlag" => "N", // "storedCardUniqueID" => "{{guid}}" // ], "installmentPaymentDetails" => [ "ippFlag" => "N"//, // "installmentPeriod" => 0, // "interestType" => null ], "mcpFlag" => "N", "request3dsFlag" => "N", "transactionAmount" => [ "amountText" => "000000000100", "currencyCode" => "THB", "decimalPlaces" => 2, "amount" => 1 ], "channelCode" => "WEBPAY",//fix "autoRedirectDelayTimer"=> 5, //ตามต้องการว่าจะให้กลับมาที่หน้า ม.ราม กี่นาที "notificationURLs" => [ "confirmationURL" => "http://example-confirmation.com", "failedURL" => "http://example-failed.com", "cancellationURL" => "http://example-cancellation.com", "backendURL" => "http://example-backend.com" ], // "deviceDetails" => [ // "browserIp" => "1.0.0.1", // "browser" => "Postman Browser", // "browserUserAgent" => "PostmanRuntime/7.26.8 - not from header", // "mobileDeviceFlag" => "N" // ], // "purchaseItems" => [ // [ // "purchaseItemType" => "ticket", // "referenceNo" => "2322460376026", // "purchaseItemDescription" => "Bundled insurance", // "purchaseItemPrice" => [ // "amountText" => "000000100000", // "currencyCode" => "THB", // "decimalPlaces" => 2, // "amount" => 1000 // ], // "subMerchantID" => "string", // "passengerSeqNo" => 1 // ] // ], // "customFieldList" => [ // [ // "fieldName" => "TestField", // "fieldValue" => "This is test" // ] // ] "recurringPaymentDetails" => [ "rppFlag"=>"N" // fix ] ]; $payload = [ "aud" => "PacoAudience", "iss" => SecurityData::$AccessToken, //apikey "request" => $request, //"CompanyApiKey" => SecurityData::$AccessToken, "exp" => $now->addHour()->unix(), "iat" => $now->unix(), "nbf" => $now->unix(), ]; $stringPayload = json_encode($payload); echo("stringPayload"."<br>"); var_dump($stringPayload); $signingKey = $this->GetPrivateKey(SecurityData::$MerchantSigningPrivateKey); print_r($signingKey); $encryptingKey = $this->GetPublicKey(SecurityData::$PacoEncryptionPublicKey); print_r($encryptingKey); $body = $this->EncryptPayload($stringPayload, $signingKey, $encryptingKey); echo("body"."<br>"); var_dump($body); //third-party http client https://github.com/guzzle/guzzle //$response = $this->client->post('api/1.0/Payment/NonUi', [ $response = $this->client->post('https://core.demo-paco.2c2p.com/api/1.0/Payment/prePaymentUi', [ 'headers' => [ //'Accept' => 'application/jose', //'CompanyApiKey' => SecurityData::$AccessToken, // 'Content-Type' => 'application/jose; charset=utf-8', 'alg' => SecurityData::$JWEAlgorithm, 'enc' => SecurityData::$JWEEncrptionAlgorithm, 'kid' => SecurityData::$EncryptionKeyId, 'typ' => SecurityData::$TokenType, ], 'body' => $body ]); $token = $response->getBody()->getContents(); $decryptingKey = $this->GetPrivateKey(SecurityData::$MerchantDecryptionPrivateKey); $signatureVerificationKey = $this->GetPublicKey(SecurityData::$PacoSigningPublicKey); return $this->DecryptToken($token, $decryptingKey, $signatureVerificationKey); } } ?>