Beispiel #1
0
 function __construct($isCashPayment = false, $credentials = array())
 {
     PayU::$language = SupportedLanguages::ES;
     //Seleccione el idioma.
     if (sizeof($credentials) > 0) {
         if (isset($credentials['accountID'])) {
             $this->setAccountID($credentials['accountID']);
         }
         if (isset($credentials['apiKey'])) {
             $this->setApiKey($credentials['apiKey']);
         }
         if (isset($credentials['apiLogin'])) {
             $this->setApiLogin($credentials['apiLogin']);
         }
         if (isset($credentials['merchantId'])) {
             $this->setMerchantId($credentials['merchantId']);
         }
     }
     // URL de Pagos
     Environment::setPaymentsCustomUrl("https://api.payulatam.com/payments-api/4.0/service.cgi");
     // URL de Consultas
     Environment::setReportsCustomUrl("https://api.payulatam.com/reports-api/4.0/service.cgi");
     // URL de Suscripciones para Pagos Recurrentes
     Environment::setSubscriptionsCustomUrl("https://api.payulatam.com/payments-api/rest/v4.3/");
     //Informacion para conexion de SDK
     PayU::$apiKey = $this->getApiKey();
     PayU::$apiLogin = $this->getApiLogin();
     PayU::$merchantId = $this->getMerchantId();
 }
 static function do_payment($order_id, $description, $total, $email, $name, $dni, $card_number, $cvv, $expiration_Date, $offline_store, $is_offline)
 {
     require_once __DIR__ . '/payu/PayU.php';
     try {
         $gp_options = get_option('woocommerce_GP_PayU_offline_Gateway_settings');
         PayU::$apiKey = $gp_options['api_key'];
         PayU::$apiLogin = $gp_options['api_login'];
         PayU::$merchantId = $gp_options['merchant_id'];
         PayU::$language = SupportedLanguages::ES;
         PayU::$isTest = $gp_options['environment'] == 'yes';
         if (PayU::$isTest == true) {
             Environment::setPaymentsCustomUrl("https://stg.api.payulatam.com/payments-api/4.0/service.cgi");
             Environment::setReportsCustomUrl("https://stg.api.payulatam.com/reports-api/4.0/service.cgi");
             $name = 'APPROVED';
         } else {
             Environment::setPaymentsCustomUrl("https://api.payulatam.com/payments-api/4.0/service.cgi");
             Environment::setReportsCustomUrl("https://api.payulatam.com/reports-api/4.0/service.cgi");
         }
         if ($is_offline == false) {
             if (preg_match('/^3[47][0-9]{13}$/', $card_number)) {
                 $paymentMethod = PaymentMethods::AMEX;
             } elseif (preg_match('/^5[1-5][0-9]{14}$/', $card_number)) {
                 $paymentMethod = PaymentMethods::MASTERCARD;
             } elseif (preg_match('/^4[0-9]{12}(?:[0-9]{3})?$/', $card_number)) {
                 $paymentMethod = PaymentMethods::VISA;
             }
         } else {
             PayU::$isTest = false;
             if ($offline_store == 'oxxo') {
                 $paymentMethod = PaymentMethods::OXXO;
             } elseif ($offline_store == 'seveneleven') {
                 $paymentMethod = PaymentMethods::SEVEN_ELEVEN;
             }
         }
         $reference_code = date("Ymd His - ") . $order_id;
         $base_parameters = array(PayUParameters::ACCOUNT_ID => PayU_Middleware::$account_id, PayUParameters::REFERENCE_CODE => $reference_code, PayUParameters::DESCRIPTION => $description, PayUParameters::VALUE => $total, PayUParameters::CURRENCY => "MXN", PayUParameters::BUYER_EMAIL => $email, PayUParameters::PAYER_DNI => $dni, PayUParameters::PAYMENT_METHOD => $paymentMethod, PayUParameters::COUNTRY => PayUCountries::MX, PayUParameters::EXPIRATION_DATE => "2016-09-27T00:00:00", PayUParameters::IP_ADDRESS => $_SERVER['REMOTE_ADDR'], PayUParameters::PAYER_NAME => $name);
         $online_parameters = array(PayUParameters::CREDIT_CARD_NUMBER => $card_number, PayUParameters::CREDIT_CARD_EXPIRATION_DATE => $expiration_Date, PayUParameters::CREDIT_CARD_SECURITY_CODE => $cvv, PayUParameters::PAYER_EMAIL, $email, PayUParameters::INSTALLMENTS_NUMBER => "1", PayUParameters::COUNTRY => PayUCountries::MX, PayUParameters::DEVICE_SESSION_ID => "vghs6tvkcle931686k1900o6e1", PayUParameters::PAYER_COOKIE => "11pt1t38347bs6jc9ruv2ecpv7o2", PayUParameters::USER_AGENT => $_SERVER['HTTP_USER_AGENT']);
         if ($is_offline == false) {
             $parameters = array_merge($base_parameters, $online_parameters);
         } else {
             $parameters = $base_parameters;
         }
         $response = PayUPayments::doAuthorizationAndCapture($parameters);
         if ($response) {
             $res = array('provider' => 'payu', 'order_id' => $order_id, 'reference_code' => $reference_code, 'state' => $response->transactionResponse->state, 'transaction_id' => $response->transactionResponse->transactionId, 'code' => $response->code, 'pending_reason' => $response->transactionResponse->pendingReason, 'payment_url' => $response->transactionResponse->extraParameters->URL_PAYMENT_RECEIPT_HTML, 'response_json' => json_encode($response));
             do_action('gp_order_completed', json_encode($res));
             return $res;
         }
     } catch (PayUException $e) {
         do_action('gp_error_occurred', json_encode($e));
         throw new Exception(__('PayU. ' . $e, 'GP_PayU_offline_Gateway'));
     } catch (Exception $e) {
         do_action('gp_error_occurred', json_encode($e));
         throw new Exception(__('Generic. ' . $e, 'GP_PayU_offline_Gateway'));
     }
 }
Beispiel #3
0
<?php

/**
 * OK
 * BANK_REFERENCED --bank payment
 * @author nick
 * @since 2015/12/09
 * 
 */
require_once 'payulib/PayU.php';
$startTime = date('Y-m-d H:i:s');
PayU::$apiKey = "6u39nqhq8ftd0hlvnjfs66eh8c";
PayU::$merchantId = "500238";
PayU::$apiLogin = "******";
PayU::$language = SupportedLanguages::ES;
PayU::$isTest = false;
Environment::setPaymentsCustomUrl("https://stg.api.payulatam.com/payments-api/4.0/service.cgi");
// Queries URL
Environment::setReportsCustomUrl("https://stg.api.payulatam.com/reports-api/4.0/service.cgi");
// Subscriptions for recurring payments URL
Environment::setSubscriptionsCustomUrl("https://stg.api.payulatam.com/payments-api/rest/v4.3/");
//---------------get order by order_test.php--------------------------
$filename = 'createOrderId.php';
$handle = fopen($filename, "r");
$order_id = fread($handle, filesize($filename));
fclose($handle);
$netOrder = $order_id + 1;
file_put_contents($filename, $netOrder);
//orderid = orderid + 1 in order_test.php
//---------------get order by order_test.php--------------------------
$reference = "comprame_test_" . $order_id;
Beispiel #4
0
 private function orderVerify($value)
 {
     $response = new stdClass();
     if (empty($value)) {
         $response->status = "Empty Value";
         $response->status_code = 201;
     } else {
         $response->status_code = 202;
     }
     require_once 'plugin/payu_sdk/PayU.php';
     Environment::setPaymentsCustomUrl("https://api.payulatam.com/payments-api/4.0/service.cgi");
     Environment::setReportsCustomUrl("https://api.payulatam.com/reports-api/4.0/service.cgi");
     Environment::setSubscriptionsCustomUrl("https://api.payulatam.com/payments-api/rest/v4.3/");
     $commerce = $this->getDataCommerce();
     PayU::$apiKey = $commerce->data['APIKEY'];
     // apiKey.
     PayU::$apiLogin = $commerce->data['APILOGIN'];
     // apiLogin.
     PayU::$merchantId = $commerce->data['MERCHANTID'];
     // Id de Comercio.
     PayU::$language = SupportedLanguages::ES;
     //Seleccione el idioma.
     PayU::$isTest = true;
     //Dejarlo True cuando sean pruebas.
     $transaction = new stdClass();
     // Código de referencia de la orden.
     $parameters = array(PayUParameters::REFERENCE_CODE => $value);
     $response_payu = PayUReports::getOrderDetailByReferenceCode($parameters);
     foreach ($response_payu as $order) {
         $order->accountId;
         $order->status;
         $order->referenceCode;
         $order->additionalValues->TX_VALUE->value;
         $order->additionalValues->TX_TAX->value;
         if ($order->buyer) {
             $order->buyer->emailAddress;
             $order->buyer->fullName;
         }
         $transactions = $order->transactions;
         foreach ($transactions as $transaction) {
             $transaction->type;
             $transaction->transactionResponse->state;
             $transaction->transactionResponse->paymentNetworkResponseCode;
             $transaction->transactionResponse->trazabilityCode;
             $transaction->transactionResponse->responseCode;
             if ($transaction->payer) {
                 $transaction->payer->fullName;
                 $transaction->payer->emailAddress;
             }
         }
     }
     $result = $this->updateDataCommerceByReference($value, $transaction);
     $response->answer = $transaction;
     $response->status_code = 200;
     $response->status = $result->status;
     return $response;
 }
 public function complete(Request $request)
 {
     $carts = \App\Cart::whereUserId($this->user()->id)->get();
     if (!count($carts)) {
         return redirect(route('home.index'));
     }
     $payuResponse = "";
     $order = new \App\Order();
     $order->user_id = $this->user()->id;
     $order->date_time = date('Y-m-d H:i:s');
     $order->save();
     try {
         //documentación
         //http://developers.payulatam.com/es/api/sandbox.html
         //https://github.com/mauricio067/integracion-payu-php
         require_once '../resources/libs/payu/PayU.php';
         //URL de Pagos
         \Environment::setPaymentsCustomUrl("https://stg.api.payulatam.com/payments-api/4.0/service.cgi");
         \PayU::$apiKey = "6u39nqhq8ftd0hlvnjfs66eh8c";
         \PayU::$apiLogin = "******";
         \PayU::$merchantId = "500238";
         \PayU::$language = \SupportedLanguages::ES;
         \PayU::$isTest = true;
         //Parámetros básicos de pago
         $prefix = env('APP_ENV') == 'production' ? 'PED' : 'TEST';
         $parameters = array(\PayUParameters::REFERENCE_CODE => $prefix . str_pad($order->id, 10, '0', STR_PAD_LEFT), \PayUParameters::COUNTRY => \PayUCountries::PE, \PayUParameters::ACCOUNT_ID => "500546", \PayUParameters::CURRENCY => "USD", \PayUParameters::DESCRIPTION => $this->user()->cart_description, \PayUParameters::VALUE => $this->user()->total_cart_amount);
         //Datos tarjeta de crédito
         $parameters[\PayUParameters::INSTALLMENTS_NUMBER] = 1;
         //Número de cuotas
         $parameters[\PayUParameters::PAYER_NAME] = $request->get('name', '');
         //$this->user()->name;
         $parameters[\PayUParameters::CREDIT_CARD_NUMBER] = $request->get('number', '');
         $parameters[\PayUParameters::CREDIT_CARD_EXPIRATION_DATE] = $request->get('expiration', '');
         $parameters[\PayUParameters::CREDIT_CARD_SECURITY_CODE] = $request->get('cvv', '');
         $parameters[\PayUParameters::PROCESS_WITHOUT_CVV2] = false;
         $parameters[\PayUParameters::PAYMENT_METHOD] = 'VISA';
         $payuResponse = \PayUPayments::doAuthorizationAndCapture($parameters);
         if (isset($payuResponse->code) && $payuResponse->code == 'SUCCESS') {
             if (isset($payuResponse->transactionResponse->state) && $payuResponse->transactionResponse->state == 'APPROVED') {
                 if ($this->generateTickets($order, $payuResponse)) {
                     \Mail::queue('email.order', ['order' => $order], function ($message) use($order) {
                         $message->to($order->user->email);
                     });
                     return redirect(route('user.orders'));
                 }
             } else {
                 $order->data = json_encode($payuResponse);
                 $order->status = 'error';
                 $order->save();
                 return redirect(route('checkout.error'))->with('order', $order);
             }
         } else {
             $order->data = json_encode($payuResponse);
             $order->status = 'error';
             $order->save();
             return redirect(route('checkout.error'))->with('order', $order);
         }
     } catch (\Exception $ex) {
         $order->data = $ex->getMessage();
         $order->status = 'error';
         $order->save();
         return redirect(route('checkout.error'))->with('order', $order);
     }
 }