Пример #1
0
<?php

date_default_timezone_set('America/Chicago');
require_once 'lib/Braintree.php';
Braintree_Configuration::environment('sandbox');
Braintree_Configuration::merchantId('5xwqxqd7pkqwxfjs');
Braintree_Configuration::publicKey('8pfkt34wzyvrnnwy');
Braintree_Configuration::privateKey('8b63a0ae59085a11912527848633b848');
$output = fopen('transaction_report.csv', 'w');
fputcsv($output, ['id', 'type', 'amount', 'status', 'created_at', 'service_fee_amount', 'merchant_account_id']);
$now = new DateTime();
$yesterday = $now->modify('-365 day');
$transactions = Braintree_Transaction::search([Braintree_TransactionSearch::settledAt()->greaterThanOrEqualTo($yesterday)]);
foreach ($transactions as $transaction) {
    $id = $transaction->id;
    $type = $transaction->type;
    $amount = $transaction->amount;
    $status = $transaction->status;
    $createdAt = $transaction->createdAt->format('d/m/Y H:i:s');
    $serviceFeeAmount = $transaction->serviceFeeAmount;
    $merchantAccountId = $transaction->merchantAccountId;
    $csvrow = [$id, $type, $amount, $status, $createdAt, $serviceFeeAmount, $merchantAccountId];
    fputcsv($output, $csvrow);
}
echo "Download the CSV file <a href='transaction_report.csv'>Download</a>";
 function test_rangeNode_settledAt()
 {
     $transaction = Braintree_Transaction::saleNoValidate(array('amount' => '1000.00', 'creditCard' => array('number' => '4111111111111111', 'expirationDate' => '05/12'), 'options' => array('submitForSettlement' => true)));
     Braintree_Http::put('/transactions/' . $transaction->id . '/settle');
     $transaction = Braintree_Transaction::find($transaction->id);
     $twenty_min_ago = date_create("now -20 minutes", new DateTimeZone("UTC"));
     $ten_min_ago = date_create("now -10 minutes", new DateTimeZone("UTC"));
     $ten_min_from_now = date_create("now +10 minutes", new DateTimeZone("UTC"));
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::id()->is($transaction->id), Braintree_TransactionSearch::settledAt()->between($twenty_min_ago, $ten_min_ago)));
     $this->assertEquals(0, $collection->maximumCount());
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::id()->is($transaction->id), Braintree_TransactionSearch::settledAt()->between($ten_min_ago, $ten_min_from_now)));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($transaction->id, $collection->firstItem()->id);
 }