Last active
December 16, 2021 05:15
-
-
Save lupena/8d08ed04b1cb91265cda1d4c887db664 to your computer and use it in GitHub Desktop.
Class to handle Azul Payment Gateway Methods / Banco Popular Dominicano BPD / Azul.com.do
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* PHP version 5 | |
* @package AzulPaymentGateway | |
* @author ideologic SRL <touch@ideologic.do> | |
* @since File available since Release 1 | |
*/ | |
<?php namespace App; | |
// use Illuminate\Database\Eloquent\Model; | |
// use DB; | |
// use Auth; | |
// use Illuminate\Support\Collection; | |
// use Mail; | |
// use Illuminate\Support\Str; | |
// use \Hash; | |
use GuzzleHttp\Exception\GuzzleException; | |
use GuzzleHttp\Client; | |
/* | |
* Handle Azul Payment Gateway Methods. | |
* Integration with Banco Popular Dominicano / Azul.com.do Payment Processor | |
*/ | |
class AzulPaymentGateway { | |
public static $method = "JSON"; | |
public static $RootDomain = "https://pagos.azul.com.do/webservices/"; | |
/* | |
* Method: submitPayment | |
* Params | |
* $OrderNumber Number(15) | |
* $Store String(11) | |
* $Akey1 String | |
* $Akey2 String | |
* $CardHolder String | |
* $CardNumber Number(19) | |
* $ExpirationDate Number(6) | |
* $CVC Number(3) | |
* $Amount Number(12) -- (Tax included) & Last two digits represents decimals | |
* $Tax Number(12) -- Last two digits represents decimals | |
*/ | |
public static function submitPayment($OrderNumber, $Store, $Akey1, $Akey2, $CardHolder, $CardNumber, $ExpirationDate, $CVC, $Amount, $Tax ) | |
{ | |
$RequestUri = self::$RootDomain . self::$method . '/Default.aspx'; | |
$RequestObject = new \stdClass(); | |
$RequestObject->Channel = "EC"; | |
$RequestObject->Store = $Store; | |
$RequestObject->CardNumber = $CardNumber; | |
$RequestObject->Expiration = $ExpirationDate; | |
$RequestObject->CVC = $CVC; | |
$RequestObject->PosInputMode = "E-Commerce"; | |
$RequestObject->TrxType = "Sale"; | |
$RequestObject->Amount = $Amount; | |
$RequestObject->Itbis = $Tax; | |
$RequestObject->CurrencyPosCode = "$"; | |
$RequestObject->Payments = "1"; | |
$RequestObject->Plan = "0"; | |
$RequestObject->AcquirerRefData = "1"; | |
$RequestObject->CustomerServicePhone = "809-999-9999"; // Replace for your Phone no. | |
$RequestObject->OrderNumber = $OrderNumber; | |
$RequestObject->ECommerceUrl = "http://ideologic.do"; // Replace for your url. | |
$RequestObject->CustomOrderId = $OrderNumber; | |
try { | |
$client = new Client(); //GuzzleHttp\Client | |
$result = $client->post($RequestUri, [ | |
'headers' => [ | |
"Content-type" => "application/json", | |
"Auth1" => $Akey1, | |
"Auth2" => $Akey2 | |
], | |
'json' => $RequestObject, | |
'cert' => base_path().'/resources/cert/azul_cert.pem', | |
'ssl_key' => base_path().'/resources/cert/ssl_key_cert.pem' | |
]); | |
//Prot. Respuesta. | |
$rtn = new \stdClass(); | |
$rtn->status = false; | |
$rtn->responseMessage = "Pago no procesado."; | |
$rtn->AuthorizationCode = "0"; | |
} | |
catch (GuzzleHttp\Exception\ClientException $e) { | |
$response = $e->getResponse(); | |
$result = $response->getBody(); | |
// Life is too short to handle exceptions. | |
} | |
$result = json_decode($result->getBody()); | |
// Create a log for the transaction. | |
// self::logTransaction($OrderNumber, $result->AuthorizationCode, $result->ResponseCode, $result->ResponseMessage, $result->RRN, $result->LotNumber, $result->IsoCode, $result->ErrorDescription, $result->DateTime, $result->Ticket, $CardHolder, $RequestObject ); | |
if ($result->ResponseCode == "ISO8583" && $result->IsoCode == "00"){ | |
$rtn->status = true; | |
$rtn->responseMessage = $result->ResponseMessage; | |
$rtn->AuthorizationCode = $result->AuthorizationCode; | |
}else{ | |
// If the message was not succesful, return error detail: | |
$rtn->responseMessage = $result->ResponseMessage ." ". $result->ErrorDescription; | |
} | |
return $rtn; | |
} | |
/* | |
* | |
* Transaction Logs | |
* | |
*/ | |
public static function logTransaction( $idorden, $AuthorizationCode, $responsecode, $responsemessage, $rnn, $lotnumber, $isocode, $errordescription, $datetime, $ticket, $CardHolder, $inputparameters) | |
{ | |
// $MaskedCard = 'XXXX-XXXX-XXXX-' . substr($inputparameters->CardNumber, -4); | |
// Implement your own database logic. | |
} | |
} | |
BigMadCode
commented
Jun 24, 2020
via email
Sure,
…On Wed, Jun 24, 2020 at 8:05 AM Bernard Rodriguez ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hey Mpulse1,
Can you share your postman collection? I am working on a new integration.
Your help on this would be tremendous!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://gist.github.com/8d08ed04b1cb91265cda1d4c887db664#gistcomment-3352856>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFPTGTDMJVFNIZRJSUH4VJLRYHTZHANCNFSM4NIDLFNA>
.
Hey MPulse1, any luck with the collection from postman? I sent you and email to your gmail account.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment