1. Go to this page and download the library: Download starkbank/sdk 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/ */
starkbank / sdk example snippets
use StarkBank\Key;
list($privateKey, $publicKey) = Key::create();
# or, to also save .pem files in a specific path
list($privateKey, $publicKey) = Key::create("file/keys/");
use StarkBank\Project;
// Get your private key from an environment variable or an encrypted database.
// This is only an example of a private key content. You should use your own key.
$privateKeyContent = "
-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK
oUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1
IF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==
-----END EC PRIVATE KEY-----
";
$project = new Project([
"environment" => "sandbox",
"id" => "5656565656565656",
"privateKey" => $privateKeyContent
]);
use StarkBank\Organization;
// Get your private key from an environment variable or an encrypted database.
// This is only an example of a private key content. You should use your own key.
privateKeyContent = "
-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIMCwW74H6egQkTiz87WDvLNm7fK/cA+ctA2vg/bbHx3woAcGBSuBBAAK
oUQDQgAE0iaeEHEgr3oTbCfh8U2L+r7zoaeOX964xaAnND5jATGpD/tHec6Oe9U1
IF16ZoTVt1FzZ8WkYQ3XomRD4HS13A==
-----END EC PRIVATE KEY-----
";
$organization = new Organization([
"environment" => "sandbox",
"id" => "5656565656565656",
"privateKey" => $privateKeyContent,
"workspaceId" => null // You only need to set the workspaceId when you are operating a specific workspaceId
]);
// To dynamically use your organization credentials in a specific workspaceId,
// you can use the Organization::replace() method:
$balance = Balance::get(Organization::replace($organization, "4848484848484848"));
use StarkBank\Balance;
$balance = Balance::get($project); # or organization
use StarkBank\Settings;
use StarkBank\Balance;
Settings::setUser($project); # or organization
$balance = Balance::get();
use StarkBank\Settings;
Settings::setLanguage("en-US");
use StarkBank\Transaction;
$transactions = Transaction::query([
"after" => "2020-01-01",
"before" => "2020-03-01"
]);
foreach($transactions as $transaction){
print_r($transaction);
}
use StarkBank\Transaction;
$cursor = null;
while (true) {
list($page, $cursor) = Transaction::page($options = ["limit" => 5, "cursor" => $cursor]);
foreach ($page as $transaction) {
print_r($transaction);
}
if ($cursor == null) {
break;
}
}
use StarkBank\Transaction;
$transactions = Transaction::create([
new Transaction([
"amount" => 100, # (R$ 1.00)
"receiverId" => "1029378109327810",
"description" => "Transaction to dear provider",
"externalId" => "12345", # so we can block anything you send twice by mistake
"tags" => ["provider"]
]),
new Transaction([
"amount" => 234, # (R$ 2.34)
"receiverId" => "2093029347820947",
"description" => "Transaction to the other provider",
"externalId" => "12346", # so we can block anything you send twice by mistake
"tags" => ["provider"]
]),
]);
foreach($transactions as $transaction){
print_r($transaction);
}
use StarkBank\Transaction;
$transactions = Transaction::query([
"after" => "2020-01-01",
"before" => "2020-03-01"
]);
foreach($transactions as $transaction){
print_r($transaction);
}
use StarkBank\Transaction;
$transaction = Transaction::get("5155165527080960");
print_r($transaction);
use StarkBank\Balance;
$balance = Balance::get();
print_r($balance);
use StarkBank\Transfer;
$transfers = Transfer::create([
new Transfer([
"amount" => 100,
"bankCode" => "033", # TED
"branchCode" => "0001",
"accountNumber" => "10000-0",
"taxId" => "012.345.678-90",
"name" => "Tony Stark",
"tags" => ["iron", "suit"]
]),
new Transfer([
"amount" => 200,
"bankCode" => "20018183", # Pix
"branchCode" => "1234",
"accountNumber" => "123456-7",
"accountType" => "salary",
"externalId" => "my-internal-id-12345",
"taxId" => "012.345.678-90",
"name" => "Jon Snow",
"scheduled" => (new DateTime("now"))->add(new DateInterval("P1D")),
"description" => "Transaction to dear provider",
"tags" => [],
"rules" => [
new Transfer\Rule([
"key" => "resendingLimit", # Set maximum number of retries if Transfer fails due to systemic issues at the receiver bank
"value" => 5 # Our resending limit is 10 by default
])
]
])
]);
foreach($transfers as $transfer){
print_r($transfer);
}
use StarkBank\Transfer;
$transfers = Transfer::query([
"after" => "2020-01-01",
"before" => "2020-04-01"
]);
foreach($transfers as $transfer){
print_r($transfer->name);
}
use StarkBank\Transfer;
$transfer = Transfer::get("5155165527080960");
print_r($transfer);
use StarkBank\Transfer;
$transfer = Transfer::delete("5155165527080960");
print_r($transfer);
use StarkBank\Boleto;
$boleto = Boleto::delete("5155165527080960");
print_r($boleto);
use StarkBank\Boleto;
$boletos = Boleto::query([
"after" => "2020-01-01",
"before" => (new DateTime("now"))->add(new DateInterval("P1D"))
]);
foreach($boletos as $boleto){
print_r($boleto);
}
use StarkBank\Boleto;
$logs = Boleto\Log::query(["limit" => 150]);
foreach($logs as $log){
print_r($log);
}
use StarkBank\Boleto;
$log = Boleto\Log::get("5155165527080960");
print_r($log);
use StarkBank\BoletoHolmes;
$holmes = [new BoletoHolmes([
"boletoId" => "5976467733217280"
])];
$sherlock = BoletoHolmes::create($holmes)[0];
foreach($holmes as $sherlock){
print_r($sherlock);
}
use StarkBank\BoletoHolmes;
$sherlock = Boleto::get("5976467733217280");
print_r($sherlock)
use StarkBank\BoletoHolmes;
$holmes = iterator_to_array(Boleto::query(["limit" => 10, "before" => new DateTime("now")]));
foreach($holmes as $sherlock){
print_r($sherlock);
}
use StarkBank\BoletoHolmes\Log;
$logs = iterator_to_array(Log::query(["limit" => 10, "types" => ["solving"]]));
foreach($logs as $log){
print_r($log);
}
use StarkBank\BoletoHolmes\Log;
$log = Log::get("5976467733217280");
print_r($log)
use StarkBank\BrcodePayment;
$payments = BrcodePayment::create([
new BrcodePayment([
"brcode" => "00020126580014br.gov.bcb.pix0136a629532e-7693-4846-852d-1bbff817b5a8520400005303986540510.005802BR5908T'Challa6009Sao Paulo62090505123456304B14A",
"taxId" => "20.018.183/0001-80",
"description" => "Tony Stark's Suit",
"amount" => 7654321,
"scheduled" => (new DateTime("now"))->add(new DateInterval("P5D")),
"tags" => ["Stark", "Suit"],
"rules" => [
new BrcodePayment\Rule([
"key" => "resendingLimit", # Set maximum number of retries if BrcodePayment fails due to systemic issues at the receiver bank
"value" => 5 # Our resending limit is 10 by default
])
]
])
]);
foreach($payments as $payment){
print_r($payment);
}
use StarkBank\BrcodePayment;
$payment = BrcodePayment::get("19278361897236187236");
print_r($payment);