Skip to content

Instantly share code, notes, and snippets.

@danieluyo
Last active December 16, 2018 22:37
Show Gist options
  • Save danieluyo/d94ecf5beffb323e81d7d1ff2e3f0938 to your computer and use it in GitHub Desktop.
Save danieluyo/d94ecf5beffb323e81d7d1ff2e3f0938 to your computer and use it in GitHub Desktop.
Laravel Conekta Test
<?php
namespace App\Http\Controllers\Test;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Conekta\Conekta;
use Conekta\Order;
use Conekta\Charge;
class ConektaTestController extends Controller
{
private function orden()
{
$paymentOrder = [
'amount' => 100 * 100,
'currency' => 'mxn',
'description' => 'Lorem ipsum',
'customer_info' => [
'name' => 'Daniel Ejemplo',
'phone' => '7771223344',
'email' => '[email protected]'
],
'line_items' => [
[
'name' => 'Pantalla',
'description' => 'Pantalla 4k para jugar juegos jugables chidos perrones :v',
'unit_price' => 100 * 100,
'quantity' => 1,
'sku' => 'PANTALLA4k0001'
]
]
];
return $paymentOrder;
}
private function ordenPay()
{
$paymentOrder = [
'amount' => 100 * 100,
'currency' => 'mxn',
'description' => 'Lorem ipsum',
'details' => [
'name' => 'Daniel Ejemplo',
'phone' => '7771223344',
'email' => '[email protected]',
'line_items' => [
[
'name' => 'Pantalla',
'description' => 'Pantalla 4k para jugar juegos jugables chidos perrones :v',
'unit_price' => 100 * 100,
'quantity' => 1,
'sku' => 'PANTALLA4k0001'
]
]
]
];
return $paymentOrder;
}
private function orderCreate($paymentOrder)
{
$orden = Order::create($paymentOrder);
dd($orden);
}
private function chargeCreate($paymentOrder)
{
$cargo = Charge::create($paymentOrder);
dd( $cargo );
}
public function tarjeta()
{
Conekta::setApiKey(env('CONEKTA_DEBUG'));
Conekta::setApiVersion('2.0.0');
Conekta::setLocale('es');
$paymentOrder = self::orden();
$paymentOrder['charges'][] = [
'payment_method' => [
'token_id' => 'tok_test_visa_4242',
'type' => 'card'
]
];
self::orderCreate($paymentOrder);
}
public function banorte()
{
Conekta::setApiKey(env('CONEKTA_DEBUG'));
Conekta::setApiVersion('2.0.0');
Conekta::setLocale('es');
$paymentOrder = self::orden();
$paymentOrder['charges'][] = [
'payment_method' => [
'token_id' => 'tok_test_visa_4242',
'type' => 'banorte'
]
];
self::orderCreate($paymentOrder);
}
public function spei()
{
Conekta::setApiKey(env('CONEKTA_DEBUG'));
Conekta::setApiVersion('2.0.0');
Conekta::setLocale('es');
$paymentOrder = self::orden();
$paymentOrder['charges'][] = [
'payment_method' => [
'type' => 'spei'
]
];
self::orderCreate($paymentOrder);
}
public function oxxoPay()
{
Conekta::setApiKey(env('CONEKTA_DEBUG'));
Conekta::setApiVersion('2.0.0');
Conekta::setLocale('es');
$paymentOrder = self::orden();
$paymentOrder['charges'][] = [
'payment_method' => [
'type' => 'oxxo_cash',
'expires_at' => strtotime( date('Y-m-d 23:59:59') )
]
];
self::orderCreate($paymentOrder);
}
public function msi()
{
Conekta::setApiKey(env('CONEKTA_DEBUG'));
Conekta::setApiVersion('2.0.0');
Conekta::setLocale('es');
$paymentOrder = self::orden();
$paymentOrder['amount'] = 300 * 100;
$paymentOrder['line_items'][0]['unit_price'] = 300 * 100;
$paymentOrder['charges'][] = [
'payment_method' => [
'monthly_installments' => 3,
'token_id' => 'tok_test_visa_4242',
'type' => 'card'
]
];
self::orderCreate($paymentOrder);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment