-
-
Save luismts/8faf5b911d10c51123835364884673ff 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 <[email protected]> | |
* @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. | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment