PHP code example of betalabs / pagarme-php
1. Go to this page and download the library: Download betalabs/pagarme-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
betalabs / pagarme-php example snippets
$apiKey = 'ak_test_grXijQ4GicOa2BLGZrDRTR5qNQxJW0';
$pagarMe = new \PagarMe\Sdk\PagarMe($apiKey);
$amount = 1000;
$installments = 1;
$capture = true;
$postbackUrl = 'http://requestb.in/pkt7pgpk';
$metadata = ['idProduto' => 13933139];
$customer = new \PagarMe\Sdk\Customer\Customer(
[
'name' => 'John Dove',
'email' => '[email protected] ',
'document_number' => '09130141095',
'address' => [
'street' => 'rua teste',
'street_number' => 42,
'neighborhood' => 'centro',
'zipcode' => '01227200',
'complementary' => 'Apto 42',
'city' => 'São Paulo',
'state' => 'SP',
'country' => 'Brasil'
],
'phone' => [
'ddd' => "15",
'number' =>"987523421"
],
'born_at' => '15021994',
'sex' => 'M'
]
);
$card = $pagarMe->card()->create(
'4242424242424242',
'JOHN DOVE',
'0722'
);
$recipient1 = $pagarMe->recipient()->get('re_civb4p9l7004xbm6dhsetkpj8');
$recipient2 = $pagarMe->recipient()->get('re_civb4o6zr003u3m6e8dezzja6');
$splitRule1 = $pagarMe->splitRule()->percentageRule(
40,
$recipient1,
true, // liable
true, // chargeProcessingFee,
true // chargeReminder
);
$splitRule2 = $pagarMe->splitRule()->percentageRule(
60,
$recipient,
true, // liable
true, // chargeProcessingFee,
false // chargeReminder
);
$splitrules = new PagarMe\Sdk\SplitRule\SplitRuleCollection();
$splitrules[0] = $splitRule1;
$splitrules[1] = $splitRule2;
// Credit Card Transaction
$transaction = $pagarMe->transaction()->creditCardTransaction(
$amount,
$card,
$customer,
$installments,
$capture,
$postbackUrl,
$metadata,
["split_rules" => $splitrules]
);
// Boleto Transaction
$transaction2 = $pagarMe->transaction()->boletoTransaction(
$amount,
$customer,
$postbackUrl,
$metadata,
["split_rules" => $splitrules]
);
$transaction = $pagarMe->transaction()->get(4752390);
$amountToCapture = 1000;
$metadata = ['idProduto' => '123']; // Parâmetro opcional
$splitRules = new \PagarMe\Sdk\SplitRule\SplitRuleCollection(); // Parâmetro opcional
$recipient1 = $pagarMe->recipient()->get('re_cjqgt03fv02bq4k6e3xbxxbia');
$recipient2 = $pagarMe->recipient()->get('re_cjm0lfmy3001zaq6espflawv2');
$splitRule1 = $pagarMe->splitRule()->percentageRule(
40,
$recipient1,
true, // liable
true, // chargeProcessingFee,
true // chargeReminder
);
$splitRule2 = $pagarMe->splitRule()->percentageRule(
60,
$recipient2,
true, // liable
true, // chargeProcessingFee,
false // chargeReminder
);
$splitRules[] = $splitRule1;
$splitRules[] = $splitRule2;
$pagarMe->transaction()->capture($transaction, $amountToCapture, $metadata, $splitRules);
$transaction = $pagarMe->transaction()->get("1627830");
// Credit Card Refund
$transaction = $pagarMe->transaction()->creditCardRefund($transaction);
// Boleto Refund
$bankAccount = $pagarMe->bankAccount()->create(
'341',
'0932',
'58054',
'5',
'26268738888',
'API BANK ACCOUNT',
'1'
);
$transaction = $pagarMe->transaction()->boletoRefund($transaciton, $bankAccount);
$transaction = $pagarMe->transaction()->get("1627835");
$amountRefunded = 20000;
// Credit card
$transaction = $pagarMe->transaction()->creditCardRefund(
$transaction,
$amountRefunded
);
// Boleto
$transaction = $pagarMe->transaction()->boletoRefund(
$transaciton,
$bankAccount,
$amountRefunded
);
$transactionList = $pagarMe->transaction()->getList($page, $count);
$transactionId = "1627864";
$transaction = $pagarMe->transaction()->get($transactionId);
$transactionId = "1627864";
$transaction = $pagarMe->transaction()->get($transactionId);
$transactionEvents = $pagarMe->transaction()->events($transaction);
$amount = 10000;
$rate = 13;
$rateFreeInstallments = 1;
$maxInstallments = 12;
$installments = $pagarMe->calculation()->calculateInstallmentsAmount(
$amount,
$rate,
$rateFreeInstallments,
$maxInstallments
);
$totalAmount = $installments[2]["total_amount"];
$installmentAmount = $installments[2]["installment_amount"];
$transaction = $pagarMe->transaction()->payTransaction(1627871);
//Create with card data
$cardNumber = '4242424242424242';
$cardHolderName = 'Aardvark Silva';
$cardExpirationDate = '1122';
$cardCvv = 123;
$card = $pagarMe->card()->create(
$cardNumber,
$cardHolderName,
$cardExpirationDate,
$cardCvv
);
//Create with card_hash
$card = $pagarMe->card()->createFromHash('card_hash');
$cardId = 'card_cj428xxsx01dt3f6dvre6belx';
$card = $pagarMe->card()->get(cardId);
$amount = 15000;
$days = 30;
$name = 'The Pro Plan - Platinum - Best Ever';
$trialDays = 0;
$paymentsMethods = ['credit_card', 'boleto'];
$charges = null;
$installments = 1;
$plan = $pagarMe->plan()->create(
$amount,
$days,
$name,
$trialDays,
$paymentsMethods,
$charges,
$installments
);
$plans = $pagarMe->plan()->getList($page, $count);
$plan = $pagarMe->plan()->get(164526);
$oldPlan = $pagarMe->plan()->get(163871);
$oldPlan->setName('The Pro Plan - Susan');
$oldPlan->setTrialDays('7');
$newPlan = $pagarMe->plan()->update($oldPlan);
$planId = 136869;
$plan = $pagarMe->plan()->get($planId);
$cardId = 'card_cizri9czn00csfi6e1ygzw9vz';
$card = $pagarMe->card()->get($cardId);
$metadata = ['idAssinatura' => '123'];
$extraAttributtes = [
'soft_descriptor' => 'Minha empresa'
];
$postbackUrl = 'http://requestb.in/zyn5obzy';
$customer = new \PagarMe\Sdk\Customer\Customer(
[
'name' => 'John Dove',
'email' => '[email protected] ',
'document_number' => '09130141095',
'address' => new \PagarMe\Sdk\Customer\Address([
'street' => 'rua teste',
'street_number' => 42,
'neighborhood' => 'centro',
'zipcode' => '01227200',
'complementary' => 'Apto 42',
'city' => 'São Paulo',
'state' => 'SP',
'country' => 'Brasil'
]),
'phone' => new \PagarMe\Sdk\Customer\Phone([
'ddd' => "15",
'number' =>"987523421"
]),
'born_at' => '15021994',
'sex' => 'M'
]
);
// Credit card subscription
$subscription = $pagarMe->subscription()->createCardSubscription(
$plan,
$card,
$customer,
$postbackUrl,
$metadata,
$extraAttributes
);
// Boleto Subscription
$subscription = $pagarMe->subscription()->createBoletoSubscription(
$transaction,
$customer,
$postbackUrl,
$metadata,
$extraAttributtes
);
$planId = 136869;
$plan = $pagarMe->plan()->get($planId);
$cardId = 'card_cizri9czn00csfi6e1ygzw9vz';
$card = $pagarMe->card()->get($cardId);
$metadata = ['idAssinatura' => '123'];
$postbackUrl = 'http://requestb.in/zyn5obzy';
$customer = new \PagarMe\Sdk\Customer\Customer(
[
'name' => 'John Dove',
'email' => '[email protected] ',
'document_number' => '09130141095',
'address' => new \PagarMe\Sdk\Customer\Address([
'street' => 'rua teste',
'street_number' => 42,
'neighborhood' => 'centro',
'zipcode' => '01227200',
'complementary' => 'Apto 42',
'city' => 'São Paulo',
'state' => 'SP',
'country' => 'Brasil'
]),
'phone' => new \PagarMe\Sdk\Customer\Phone([
'ddd' => "15",
'number' =>"987523421"
]),
'born_at' => '15021994',
'sex' => 'M'
]
);
$splitRules = new \PagarMe\Sdk\SplitRule\SplitRuleCollection();
$recipient1 = $pagarMe->recipient()->get('re_cjqgt03fv02bq4k6e3xbxxbia');
$recipient2 = $pagarMe->recipient()->get('re_cjm0lfmy3001zaq6espflawv2');
$splitRule1 = $pagarMe->splitRule()->percentageRule(
40,
$recipient1,
true, // liable
true, // chargeProcessingFee,
true // chargeReminder
);
$splitRule2 = $pagarMe->splitRule()->percentageRule(
60,
$recipient2,
true, // liable
true, // chargeProcessingFee,
false // chargeReminder
);
$splitRules[] = $splitRule1;
$splitRules[] = $splitRule2;
// Credit card subscription
$subscription = $pagarMe->subscription()->createCardSubscription(
$plan,
$card,
$customer,
$postbackUrl,
$metadata,
['split_rules' => $splitRules]
);
// Boleto Subscription
$subscription = $pagarMe->subscription()->createBoletoSubscription(
$transaction,
$customer,
$postbackUrl,
$metadata,
['split_rules' => $splitRules]
);
$subscription = $pagarMe->subscription()->get(205881);
$subscriptions = $pagarMe->subscription()->getList($page, $count);
$subscription = $pagarMe->subscription()->get(184577);
$newPlan = $pagarMe->plan()->get(166234);
$subscription->setPlan($newPlan);
$subscription->setPaymentMethod('credit_card');
$card = $pagarMe->card()->get('card_cj41mpuhc01bb3f6d8exeo072');
$subscription->setCard($card);
$updatedSubscription = $pagarMe->subscription()->update($subscription);
$subscriptionId = 205880;
$subscription = $pagarMe->subscription()->get($subscriptionId);
$subscription = $pagarMe->subscription()->cancel($subscription);
$subscriptionId = 205840;
$subscription = $pagarMe->subscription()->get($subscriptionId);
$transactions = $pagarMe->subscription()->transactions($subscription);
$transactionId = 1159049;
$transaction = $pagarMe->transaction()->get(transactionId);
$postbacks = $pagarMe->postback()->getList($transaction);
$transactionId = 1159049;
$transaction = $pagarMe->transaction()->get($transactionId);
$postbackId = 'po_ciat6ssga0022k06ng8vxg';
$postbacks = $pagarMe->postback()->get(
$transaction,
$postbackId
);
$transactionId = 1662527;
$transaction = $pagarMe->transaction()->get($transactionId);
$postbackId = 'po_cj4haa8l4131bpi73glgzbnpp';
$postbacks = $pagarMe->postback()->redeliver(
$transaction,
$postbackId
);
$postbackBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE'];
if ($pagarMe->postback()->validateRequest($postbackBody, $signature) {
echo "POSTback válido";
} else {
echo "POSTback inválido";
}
$balance = $pagarMe->balance()->get();
$operationList = $pagarMe->balanceOperation()->getList();
$payables = $pagarMe->payable()->getList($page, $count);
$payable = $pagarMe->payable()->get("573310");
$amount = 10000;
$recipient = $pagarMe->recipient()->get('re_citkg218g00hl8q6dh1pr5mld');
$transfer = $pagarMe->transfer()->create(
$amount,
$recipient
);
$transfers = $pagarMe->transfer()->getList($page, $count)
$transfer = $pagarMe->transfer()->get("16264");
$transfer = $pagarMe->transfer()->get("16264");
$canceledTransfer = $pagarMe->transfer()->cancel($transfer);
$recipientId = "re_ciu4jif1j007td56dsm17yew9";
$recipient = new \PagarMe\Sdk\Recipient\Recipient([
"id" => $recipientId
]);
$date = new \DateTime();
$date->add(new \DateInterval("P10D"));
$timeframe = 'end';
$requestedAmount = 13000;
$build = true;
$anticipation = $pagarMe->bulkAnticipation()->create(
$recipient,
$date,
$timeframe,
$requestedAmount,
$build
);
$recipientId = "re_ciu4jif1j007td56dsm17yew9";
$recipient = new \PagarMe\Sdk\Recipient\Recipient([
"id" => recipientId
]);
$paymentDate = new \DateTime();
$paymentDate->add(new \DateInterval("P10D"));
$timeframe = 'end';
$limits = $pagarMe->bulkAnticipation()->limits(
$recipient,
$paymentDate,
$timeframe
);
$recipient = new \PagarMe\Sdk\Recipient\Recipient([
"id" => "re_ciu4jif1j007td56dsm17yew9"
]);
$anticipation = new PagarMe\Sdk\BulkAnticipation\BulkAnticipation([
"id" => "ba_cj3uppown001gvm6dqgmjw2ce"
]);
$anticipation = $pagarMe->bulkAnticipation()->confirm(
$recipient,
$anticipation
);
$recipient = new \PagarMe\Sdk\Recipient\Recipient([
"id" => "re_ciu4jif1j007td56dsm17yew9"
]);
$anticipation = new PagarMe\Sdk\BulkAnticipation\BulkAnticipation([
"id" => "ba_cj3ur2rpl002bpn6ektsnc9lu"
]);
$anticipation = $pagarMe->bulkAnticipation()->cancel(
$recipient,
$anticipation
);
$recipient = new \PagarMe\Sdk\Recipient\Recipient([
"id" => "re_ciu4jif1j007td56dsm17yew9"
]);
$anticipation = new PagarMe\Sdk\BulkAnticipation\BulkAnticipation([
"id" => "ba_cj3us6nal0022v86daxfamp4t"
]);
$anticipation = $pagarMe->bulkAnticipation()->delete(
$recipient,
$anticipation
);
$recipietId = "re_ciu4jif1j007td56dsm17yew9";
$page = 1;
$count = 50;
$recipient = new \PagarMe\Sdk\Recipient\Recipient([
"id" => $recipientId
]);
$anticipationList = $pagarMe->bulkAnticipation()->getList(
$recipient,
$page,
$count
);
$bankCode = '341';
$agenciaNumber = '0932';
$accountNumber = '58054';
$accountDigit = '5';
$documentNumber = '26268738888';
$legalName = 'Conta Teste 2';
$agenciaDigit = '1';
$bankAccount = $pagarMe->bankAccount()->create(
$bankCode,
$agenciaNumber,
$accountNumber,
$accountDigit,
$documentNumber,
$legalName,
$agenciaDigit
);
$bankAccountId = 17411339;
$bankAccount = $pagarMe->bankAccount()->get($bankAccountId);
$bankAccounts = $pagarMe->bankAccount()->getList($page, $count);
$bankAccount = new \PagarMe\Sdk\BankAccount\BankAccount([
"id" => 17490076
]);
$transferInterval = "monthly";
$transferDay = 13;
$transferEnabled = true;
$automaticAnticipationEnabled = true;
$anticipatableVolumePercentage = 42;
$recipient = $pagarMe->recipient()->create(
$bankAccount,
$transferInterval,
$transferDay,
$transferEnabled,
$automaticAnticipationEnabled,
$anticipatableVolumePercentage
);
$recipients = $pagarMe->recipient()->getList($page, $count);
$recipientId = "re_cj3g1cml000e75f6ehjnpsl9y";
$recipient = $pagarMe->recipient()->get($recipientId);
$recipientId = "re_ciu4jif1j007td56dsm17yew9";
$recipient = new \PagarMe\Sdk\Recipient\Recipient([
"id" => $recipientId,
"anticipatable_volume_percentage" => "50",
"transfer_enabled" => true,
"transfer_interval" => "monthly",
"transfer_day" => 15,
"bank_account" => new \PagarMe\Sdk\BankAccount\BankAccount([
"id" => "17492906"
])
]);
$updatedRecipient = $pagarMe->recipient()->update(
$recipient
);
$recipientId = "re_cj3g1cml000e75f6ehjnpsl9y";
$recipient = $pagarMe->recipient()->get($recipientId);
$balance = $pagarMe->recipient()->balance($recipient);
$recipientId = "re_cj3g1cml000e75f6ehjnpsl9y";
$recipient = $pagarMe->recipient()->get($recipientId);
$balance = $pagarMe->recipient()->balanceOperations($recipient, $page, $count);
$recipientId = "re_ciu4jif1j007td56dsm17yew9";
$recipient = $pagarMe->recipient()->get($recipientId);
$balanceOperationId = 2043993;
$operation = $pagarMe->recipient()->balanceOperation($recipient, $balanceOperationId);
$customer = $pagarMe->customer()->create(
'John Dove',
'[email protected] ',
'09130141095',
/** @var $address \PagarMe\Sdk\Customer\Address */
$address,
/** @var $phone \PagarMe\Sdk\Customer\Phone */
$phone,
'15021994',
'M'
);
$customerList = $pagarMe->customer()->getList();
$customer = $pagarme->customer()->get(11222);