Created
November 20, 2019 19:12
-
-
Save vitorvargasdev/13ced9cf3e5559687de6fa94842fa84d to your computer and use it in GitHub Desktop.
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 | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use \MercadoPago; | |
class MercadoPagoController extends Controller | |
{ | |
public function index() | |
{ | |
// Configura credenciais | |
MercadoPago\SDK::setAccessToken(env('MP_AccessToken')); | |
// Cria um objeto de preferência | |
$preference = new MercadoPago\Preference(); | |
// Cria um item na preferência | |
$item = new MercadoPago\Item(); | |
$item->id = "1"; | |
$item->title = 'Bet Certa'; | |
$item->description = "instalando@disroot.org"; | |
$item->quantity = 1; | |
$item->unit_price = 20.00; | |
$item->usermail = "teste@.com"; | |
// $preference->payment_methods = array( | |
// "excluded_payment_types" => array( | |
// array("id" => "credit_card") | |
// ), | |
// ); | |
$preference->additional_info = "instalando@disroot.org"; | |
$preference->items = array($item); | |
$preference->back_urls = array( | |
"success" => "https://www.seu-site/success", | |
"failure" => "http://www.seu-site/failure", | |
"pending" => "http://www.seu-site/pending" | |
); | |
$preference->auto_return = "approved"; | |
$preference->save(); | |
// dd($preference); | |
echo $preference->id; | |
echo " | |
<form action='/processar_pagamento' method='get'> | |
<script | |
src='https://www.mercadopago.com.br/integrations/v1/web-payment-checkout.js' | |
data-preference-id='" . $preference->id . "'> | |
</script> | |
</form>"; | |
} | |
public function processar_pagamento(Request $request) | |
{ | |
return $request->all(); | |
} | |
public function check() | |
{ | |
MercadoPago\SDK::setAccessToken("TEST-537103758469246-111918-1244b8776c5e665151f0ebca777c9bca-491113493"); | |
switch (\Request::get('type')) { | |
case "payment": | |
dd(MercadoPago\Payment::find_by_id(\Request::get('id'))); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment