Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions arquivo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
'{"action":"payment.created","api_version":"v1","data":{"id":"22982928"},"date_created":"2019-12-07T17:58:58Z","id":5450141798,"live_mode":false,"type":"payment","user_id":"497947094"}'

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22982928',
),
'date_created' => '2019-12-07T17:58:58Z',
'id' => 5450141798,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22983004',
),
'date_created' => '2019-12-07T18:07:36Z',
'id' => 5450154212,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22983015',
),
'date_created' => '2019-12-07T18:08:03Z',
'id' => 5450154608,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22983033',
),
'date_created' => '2019-12-07T18:09:20Z',
'id' => 5450155644,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22983042',
),
'date_created' => '2019-12-07T18:09:39Z',
'id' => 5450155904,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22983050',
),
'date_created' => '2019-12-07T18:10:05Z',
'id' => 5450156320,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22983072',
),
'date_created' => '2019-12-07T18:12:07Z',
'id' => 5450159479,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22983095',
),
'date_created' => '2019-12-07T18:12:53Z',
'id' => 5450160839,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22982921',
),
'date_created' => '2019-12-07T17:58:16Z',
'id' => 5450164055,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

(object) array(
'action' => 'payment.created',
'api_version' => 'v1',
'data' =>
(object) array(
'id' => '22982928',
),
'date_created' => '2019-12-07T17:58:58Z',
'id' => 5450164432,
'live_mode' => false,
'type' => 'payment',
'user_id' => '497947094',
)

120 changes: 120 additions & 0 deletions assets/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
$(function(event) {
window.Mercadopago.setPublishableKey("TEST-c80f7f2a-80c8-4733-ba05-b35176a1d893");
window.Mercadopago.getIdentificationTypes();

guessingPaymentMethod(event);

addEvent(document.querySelector('#cardNumber'), 'keyup', guessingPaymentMethod);
addEvent(document.querySelector('#cardNumber'), 'change', guessingPaymentMethod);
doSubmit = false;
addEvent(document.querySelector('#pay'), 'submit', doPay);
});
function doPay(event){
event.preventDefault();
if(!doSubmit){
var $form = document.querySelector('#pay');

window.Mercadopago.createToken($form, sdkResponseHandler); // The function "sdkResponseHandler" is defined below

return false;
}
};

function sdkResponseHandler(status, response) {
if (status != 200 && status != 201) {
alert("verify filled data");
}else{
var form = document.querySelector('#pay');
var card = document.createElement('input');
card.setAttribute('name', 'token');
card.setAttribute('type', 'hidden');
card.setAttribute('value', response.id);
form.appendChild(card);
doSubmit=true;
form.submit();
}
};
function addEvent(to, type, fn){
if(document.addEventListener){
to.addEventListener(type, fn, false);
} else if(document.attachEvent){
to.attachEvent('on'+type, fn);
} else {
to['on'+type] = fn;
}
};
function getBin() {
const cardnumber = document.getElementById("cardNumber");
return cardnumber.value.substring(0,6);
};

function guessingPaymentMethod(event) {
var bin = getBin();

if (event.type == "keyup") {
if (bin.length >= 6) {
window.Mercadopago.getPaymentMethod({
"bin": bin
}, setPaymentMethodInfo);
}
} else {
setTimeout(function() {
if (bin.length >= 6) {
window.Mercadopago.getPaymentMethod({
"bin": bin
}, setPaymentMethodInfo);
}
}, 100);
}
};
function setPaymentMethodInfo(status, response) {
if (status == 200) {
const paymentMethodElement = document.querySelector('input[name=paymentMethodId]');

if (paymentMethodElement) {
paymentMethodElement.value = response[0].id;
} else {
const input = document.createElement('input');
input.setAttribute('name', 'paymentMethodId');
input.setAttribute('type', 'hidden');
input.setAttribute('value', response[0].id);

form.appendChild(input);
}

Mercadopago.getInstallments({
"bin": getBin(),
"amount": parseFloat(document.querySelector('#amount').value),
}, setInstallmentInfo);

} else {
alert(`payment method info error: ${response}`);
}
};

function setInstallmentInfo(status, response) {
var selectorInstallments = document.querySelector("#installments"),
fragment = document.createDocumentFragment();
selectorInstallments.options.length = 0;

if (response.length > 0) {
var option = new Option("Escolha...", '-1'),
payerCosts = response[0].payer_costs;

fragment.appendChild(option);

for (var i = 0; i < payerCosts.length; i++) {
fragment.appendChild(new Option(payerCosts[i].recommended_message, payerCosts[i].installments));
}

selectorInstallments.appendChild(fragment);
selectorInstallments.removeAttribute('disabled');

$("#issuer_id").prop('value', response[0].issuer.id);


//
$("#installments").prop("value", 11);
$("#pay input[type=submit]").click();
}
};
61 changes: 61 additions & 0 deletions boleto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// exit;

require_once 'vendor/autoload.php';

MercadoPago\SDK::setAccessToken("TEST-6238996572525156-120714-adc1fe90e9fe043fa4b0e3f018f42fe8-497947094");
//...
$payment = new MercadoPago\Payment();



$payment->date_of_expiration = "2018-06-30T21:52:49.000-04:00";
$payment->transaction_amount = (int)$_POST['amount'];
$payment->description = "Title of what you are paying for";
$payment->payment_method_id = "bolbradesco";
$payment->notification_url = "https://762a5e7c.ngrok.io/mp-ecommerce-php/notification.php";
$payment->payer = array(
"email" => $_POST['email'],
"first_name" => "Test",
"last_name" => "User",
"identification" => array(
"type" => "CPF",
"number" => "19119119100"
),
"address"=> array(
"zip_code" => "06233200",
"street_name" => "Av. das Nações Unidas",
"street_number" => "3003",
"neighborhood" => "Bonfim",
"city" => "Osasco",
"federal_unit" => "SP"
)
);

$payment->save();


// $payment->transaction_amount = (int)$_POST['amount'];
// $payment->token = $_POST['token'];
// $payment->description = "Lightweight Silk Watch";
// $payment->installments = (int)$_POST['installments'];
// $payment->payment_method_id = "bolbradesco";
// $payment->issuer_id = $_POST['issuer_id'];
// $payment->notification_url = "https://762a5e7c.ngrok.io/mp-ecommerce-php/notification.php";
// $payment->payer = array(
// "email" => $_POST['email']
// );
// // Save and posting the payment
// $payment->save();
//...
// Print the payment status
echo $payment->status;
//...

echo '<pre>';

print_r($payment);
Loading