PHP code example of pagarme / pagarme-php
1. Go to this page and download the library: Download pagarme/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/ */
pagarme / pagarme-php example snippets
arme = new PagarMe\Client('SUA_CHAVE_DE_API');
arme = new PagarMe\Client(
'SUA_CHAVE_DE_API',
['headers' => ['MEU_HEADER_CUSTOMIZADO' => 'VALOR HEADER CUSTOMIZADO']]
);
$transaction = $pagarme->transactions()->create([
'amount' => 1000,
'payment_method' => 'credit_card',
'card_holder_name' => 'Anakin Skywalker',
'card_cvv' => '123',
'card_number' => '4242424242424242',
'card_expiration_date' => '1220',
'customer' => [
'external_id' => '1',
'name' => 'Nome do cliente',
'type' => 'individual',
'country' => 'br',
'documents' => [
[
'type' => 'cpf',
'number' => '00000000000'
]
],
'phone_numbers' => [ '+551199999999' ],
'email' => '[email protected] '
],
'billing' => [
'name' => 'Nome do pagador',
'address' => [
'country' => 'br',
'street' => 'Avenida Brigadeiro Faria Lima',
'street_number' => '1811',
'state' => 'sp',
'city' => 'Sao Paulo',
'neighborhood' => 'Jardim Paulistano',
'zipcode' => '01451001'
]
],
'shipping' => [
'name' => 'Nome de quem receberá o produto',
'fee' => 1020,
'delivery_date' => '2018-09-22',
'expedited' => false,
'address' => [
'country' => 'br',
'street' => 'Avenida Brigadeiro Faria Lima',
'street_number' => '1811',
'state' => 'sp',
'city' => 'Sao Paulo',
'neighborhood' => 'Jardim Paulistano',
'zipcode' => '01451001'
]
],
'items' => [
[
'id' => '1',
'title' => 'R2D2',
'unit_price' => 300,
'quantity' => 1,
'tangible' => true
],
[
'id' => '2',
'title' => 'C-3PO',
'unit_price' => 700,
'quantity' => 1,
'tangible' => true
]
]
]);
$capturedTransaction = $pagarme->transactions()->capture([
'id' => 'ID_OU_TOKEN_DA_TRANSAÇÃO',
'amount' => VALOR_TOTAL_COM_CENTAVOS
]);
$refundedTransaction = $pagarme->transactions()->refund([
'id' => 'ID_OU_TOKEN_DA_TRANSAÇÃO',
]);
$partialRefundedTransaction = $pagarme->transactions()->refund([
'id' => 'ID_OU_TOKEN_DA_TRANSAÇÃO',
'amount' => 'VALOR_PARCIAL_DO_ESTORNO',
]);
$refundedTransactionWithSplit = $pagarme->transactions()->refund([
'id' => 'ID_OU_TOKEN_DA_TRANSAÇÃO',
'amount' => '6153',
'split_rules' => [
[
'id' => 'sr_cj41w9m4d01ta316d02edaqav',
'amount' => '3000',
'recipient_id' => 're_cj2wd5ul500d4946do7qtjrvk'
],
[
'id' => 'sr_cj41w9m4e01tb316dl2f2veyz',
'amount' => '3153',
'recipient_id' => 're_cj2wd5u2600fecw6eytgcbkd0',
'charge_processing_fee' => 'true'
]
]
]);
$transactions = $pagarme->transactions()->getList();
$paidTransactions = $pagarme->transactions()->getList([
'status' => 'paid'
]);
$transactions = $pagarme->transactions()->get([
'id' => 'ID_DA_TRANSAÇÃO'
]);
$transactionPayables = $pagarme->transactions()->listPayables([
'id' => 'ID_DA_TRANSAÇÃO'
]);
$transactionPayable = $pagarme->transactions()->getPayable([
'transaction_id' => 'ID_DA_TRANSAÇÃO',
'payable_id' => 'ID_DO_PAYABLE'
]);
$transactionOperations = $pagarme->transactions()->listOperations([
'id' => 'ID_DA_TRANSAÇÃO',
]);
$transactionPaymentNotify = $pagarme->transactions()->collectPayment([
'id' => 'ID_DA_TRANSAÇÃO',
'email' = > '[email protected] '
]);
$transactionEvents = $pagarme->transactions()->events([
'id' => 4262049,
]);
$calculateInstallments = $pagarme->transactions()->calculateInstallments([
'amount' => 'VALOR_DA_TRANSAÇÃO_EM_CENTAVOS',
'free_installments' => 'PARCELAS_SEM_JUROS',
'max_installments' => 'MÁXIMO_DE_PARCELAS',
'interest_rate' => 'TAXA_DE_JUROS_AO_MÊS'
]);
$paidBoleto = $pagarme->transactions()->simulateStatus([
'id' => 'ID_DA_TRANSAÇÃO',
'status' => 'paid'
]);
$refunds = $pagarme->refunds()->getList();
$transactionRefunds = $pagarme->refunds()->getList([
'transaction_id' => 'ID_DA_TRANSAÇÃO_ESTORNADA'
]);
$transactionChargebacks = $pagarme->refunds()->getList();
$card = $pagarme->cards()->create([
'holder_name' => 'Yoda',
'number' => '4242424242424242',
'expiration_date' => '1225',
'cvv' => '123'
]);
$cards = $pagarme->cards()->getList();
$visaCards = $pagarme->cards()->getList([
'brand' => 'visa'
]);
$card = $pagarme->cards()->get([
'id' => 'ID_DO_CARTÃO'
]);
$plan = $pagarme->plans()->create([
'amount' => '15000',
'days' => '30',
'name' => 'The Pro Plan - Platinum - Best ever'
]);
$plans = $pagarme->plans()->getList();
$plan = $pagarme->plans()->get(['id' => '123456']);
$updatedPlan = $pagarme->plans()->update([
'id' => '365403',
'name' => 'The Pro Plan - Susan',
'trial_days' => '7',
]);
$substription = $pagarme->subscriptions()->create([
'plan_id' => 123456,
'payment_method' => 'credit_card',
'card_number' => '4111111111111111',
'card_holder_name' => 'UNIX TIME',
'card_expiration_date' => '0722',
'card_cvv' => '123',
'postback_url' => 'http://postbacj.url',
'customer' => [
'email' => '[email protected] ',
'name' => 'Unix Time',
'document_number' => '75948706036',
'address' => [
'street' => 'Rua de Teste',
'street_number' => '100',
'complementary' => 'Apto 666',
'neighborhood' => 'Bairro de Teste',
'zipcode' => '11111111'
],
'phone' => [
'ddd' => '01',
'number' => '923456780'
],
'sex' => 'other',
'born_at' => '1970-01-01',
],
'metadata' => [
'foo' => 'bar'
]
]);
// Criando o cartão
$card = $pagarme->cards()->create([
'holder_name' => 'Yoda',
'number' => '4242424242424242',
'expiration_date' => '1225',
'cvv' => '123'
]);
$substription = $pagarme->subscriptions()->create([
'plan_id' => 365403,
'card_id' => $card->id,
'payment_method' => 'credit_card',
'postback_url' => 'http://www.pudim.com.br',
'customer' => [
'email' => '[email protected] ',
'name' => 'Unix Time',
'document_number' => '75948706036',
'address' => [
'street' => 'Rua de Teste',
'street_number' => '100',
'complementary' => 'Apto 666',
'neighborhood' => 'Bairro de Teste',
'zipcode' => '88370801'
],
'phone' => [
'ddd' => '01',
'number' => '923456780'
],
'sex' => 'other',
'born_at' => '1970-01-01',
],
'metadata' => [
'foo' => 'bar'
]
]);
$substription = $pagarme->subscriptions()->create([
'plan_id' => 123456,
'card_id' => 'card_abc123456',
'payment_method' => 'credit_card',
'postback_url' => 'http://www.pudim.com.br',
'customer' => [
'email' => '[email protected] ',
'name' => 'Unix Time',
'document_number' => '75948706036',
'address' => [
'street' => 'Rua de Teste',
'street_number' => '100',
'complementary' => 'Apto 666',
'neighborhood' => 'Bairro de Teste',
'zipcode' => '88370801'
],
'phone' => [
'ddd' => '01',
'number' => '923456780'
],
'sex' => 'other',
'born_at' => '1970-01-01',
],
'amount' => 10000,
'split_rules' => [
[
'recipient_id' => 're_abc1234abc1234abc1234abc1',
'percentage' => 20,
'liable' => true,
'charge_processing_fee' => true,
],
[
'recipient_id' => 're_abc1234abc1234abc1234abc1',
'percentage' => 80,
'liable' => true,
'charge_processing_fee' => true,
]
],
'metadata' => [
'foo' => 'bar'
]
]);
$substription = $pagarme->subscriptions()->get([
'id' => 123456
]);
$substription = $pagarme->subscriptions()->getList();
$planSubstriptions = $pagarme->subscriptions()->getList([
'plan_id' => 'ID_DO_PLANO'
]);
$updatedSubscription = $pagarme->subscriptions()->update([
'id' => 1234,
'plan_id' => 4321,
'payment_method' => 'boleto'
]);
$canceledSubscription = $pagarme->subscriptions()->cancel([
'id' => 12345
]);
$substriptionTransactions = $pagarme->subscriptions()->transactions([
'subscription_id' => 1245
]);
$settledCharges = $pagarme->subscriptions()->settleCharges([
'id' => 12345,
'charges' => 5
]);
$postbacks = $pagarme->postbacks()->getList([
'model' => 'subscription',
'model_id' => 'ID_DA_ASSINATURA'
]);
$postback = $pagarme->postbacks()->get([
'model' => 'transaction',
'model_id' => 'ID_DA_TRANSAÇÃO',
'postback_id' => 'po_cjlzhftd2006xg573fwelfg9y'
]);
$postbackRedeliver = $pagarme->postbacks()->redeliver([
'model' => 'subscription',
'model_id' => 'ID_DA_ASSINATURA',
'postback_id' => 'po_cjlzhftd2006xg573fwelfg9y'
]);
$postbackPayload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_HUB_SIGNATURE'];
$postbackIsValid = $pagarme->postbacks()->validate($postbackPayload, $signature);
$balance = $pagarme->balances()->get();
$balanceOperations = $pagarme->balanceOperations()->getList();
$balanceOperations = $pagarme->balanceOperations()->getList([
'status' => 'available'
]);
$balanceOperation = $pagarme->balanceOperations()->get([
'id' => 'BALANCE_OPERATION_ID'
]);
$payables = $pagarme->payables()->getList();
$transactionPayables = $pagarme->payables()->getList([
'transaction_id' => 'ID_DA_TRANSAÇÃO'
]);
$payable = $pagarme->payables()->get([
'id' => 'ID_DO_PAYABLE'
]);
$transfer = $pagarme->transfers()->create([
'amount' => 1000,
'recipient_id' => 're_cjeptpdyg03u3cb6elj68p5ej'
]);
$transfers = $pagarme->transfers()->getList();
$recipientTransfers = $pagarme->transfers()->getList([
'recipient_id' => 'ID_DO_RECEBEDOR'
]);
$transfer = $pagarme->transfers()->get([
'id' => 'ID_DA_TRANSFERÊNCIA'
]);
$canceledTransfer = $pagarme->transfers()->cancel([
'id' => 'ID_DA_TRANSFERÊNCIA'
]);
$anticipation = $pagarme->bulkAnticipations()->create([
'recipient_id' => 're_cjeptpdyg03u3cb6elj68p5ej',
'payment_date' => '1536883200000',
'requested_amount' => '300000',
'timeframe' => 'start'
]);
$anticipationLimits = $pagarme->bulkAnticipations()->getLimits([
'recipient_id' => 'ID_DO_RECEBEDOR',
'payment_date' => '1536883200000',
'timeframe' => 'start'
]);
$canceledAnticipation = $pagarme->bulkAnticipations()->cancel([
'recipient_id' => 'ID_DO_RECEBEDOR',
'bulk_anticipation_id' => 'ID_DA_ANTECIPAÇÃO',
]);
$anticipations = $pagarme->bulkAnticipations()->getList([
'recipient_id' => 'ID_DO_RECEBEDOR'
]);
$anticipations = $pagarme->bulkAnticipations()->getList([
'recipient_id' => 'ID_DO_RECEBEDOR',
'amount' => 'VALOR_ANTECIPADO'
]);
$bankAccount = $pagarme->bankAccounts()->create([
'bank_code' => '341',
'agencia' => '0932',
'agencia_dv' => '5',
'conta' => '58054',
'conta_dv' => '1',
'document_number' => '26268738888',
'legal_name' => 'API BANK ACCOUNT'
]);
$bankAccount = $pagarme->bankAccounts()->get([
'id' => 'ID_DA_CONTA_BANCÁRIA'
]);
$bankAccounts = $pagarme->bankAccounts()->getList();
$bankAccounts = $pagarme->bankAccounts()->getList([
'bank_code' => '341'
]);
$recipient = $pagarme->recipients()->create([
'anticipatable_volume_percentage' => '85',
'automatic_anticipation_enabled' => 'true',
'bank_account_id' => '17899179',
'transfer_day' => '5',
'transfer_enabled' => 'true',
'transfer_interval' => 'weekly'
]);
$recipients = $pagarme->recipients()->getList();
$transferEnabledRecipients = $pagarme->recipients()->getList([
'transfer_enabled' => true
]);
$recipient = $pagarme->recipients()->get([
'id' => 'ID_DO_RECEBEDOR'
]);
$updatedRecipient = $pagarme->recipients()->update([
'id' => 'ID_DO_RECEBEDOR',
'anticipatable_volume_percentage' => 80,
'transfer_day' => 4
]);
$recipientBalance = $pagarme->recipients()->getBalance([
'recipient_id' => 'ID_DO_RECEBEDOR',
]);
$recipientBalanceOperations = $pagarme->recipients()->listBalanceOperation([
'recipient_id' => 'ID_DO_RECEBEDOR'
]);
$recipientBalanceOperation = $pagarme->recipients()->getBalanceOperation([
'recipient_id' => 'ID_DO_RECEBEDOR',
'balance_operation_id' => 'ID_DA_OPERAÇÃO'
]);
$customer = $pagarme->customers()->create([
'external_id' => '#123456789',
'name' => 'João das Neves',
'type' => 'individual',
'country' => 'br',
'email' => '[email protected] ',
'documents' => [
[
'type' => 'cpf',
'number' => '11111111111'
]
],
'phone_numbers' => [
'+5511999999999',
'+5511888888888'
],
'birthday' => '1985-01-01'
]);
$customers = $pagarme->customers()->getList();
$customer = $pagarme->customers()->get([
'id' => 'ID_DO_CLIENTE'
]);
$paymentLink = $pagarme->paymentLinks()->create([
'amount' => 10000,
'items' => [
[
'id' => '1',
'title' => "Fighter's Sword",
'unit_price' => 4000,
'quantity' => 1,
'tangible' => true,
'category' => 'weapon',
'venue' => 'A Link To The Past',
'date' => '1991-11-21'
],
[
'id' => '2',
'title' => 'Kokiri Sword',
'unit_price' => 6000,
'quantity' => 1,
'tangible' => true,
'category' => 'weapon',
'venue' => "Majora's Mask",
'date' => '2000-04-27'
],
],
'payment_config' => [
'boleto' => [
'enabled' => true,
'expires_in' => 20
],
'credit_card' => [
'enabled' => true,
'free_installments' => 4,
'interest_rate' => 25,
'max_installments' => 12
],
'default_payment_method' => 'boleto'
],
'max_orders' => 1,
'expires_in' => 60
]);
$paymentLinks = $pagarme->paymentLinks()->getList();
$paymentLink = $pagarme->paymentLinks()->get([
'id' => 'ID_DO_LINK_DE_PAGAMENTO'
]);
$canceledPaymentLink = $pagarme->paymentLinks()->cancel([
'id' => 'ID_DO_LINK_DE_PAGAMENTO'
]);
$search = $pagarme->search()->get([
"type" => "transaction",
"query" => [
"query" => [
"terms" => [
"items.id" => [8, 9] // Busca transações com itens de ID 8 e 9
]
]
]
]);