예제 #1
0
function create_buyer($email_address, $card_uri)
{
    $marketplace = Balanced\Marketplace::mine();
    try {
        # new buyer
        $buyer = $marketplace->createBuyer($email_address, $card_uri);
    } catch (Balanced\Errors\DuplicateAccountEmailAddress $e) {
        # oops, account for $email_address already exists so just add the card
        $buyer = Balanced\Account::get($e->extras->account_uri);
        $buyer->addCard($card_uri);
    }
    return $buyer;
}
예제 #2
0
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY";
$account = Balanced\Account::get("/accounts/AT2V7l4MoUJH8xDse641Xqog");
예제 #3
0
 public function getUserAccount()
 {
     Yii::import('application.extensions.vendor.autoload', true);
     Httpful\Bootstrap::init();
     Balanced\Bootstrap::init();
     Balanced\Settings::$api_key = Yii::app()->params['balancedAPISecret'];
     $user = $this->getUser();
     if (!isset($user->AccountURI) || $user->AccountURI == null) {
         $account = Balanced\Marketplace::mine()->createAccount($user->Email);
         $user->AccountURI = $account->uri;
         $user->save(false);
     } else {
         $account = Balanced\Account::get($user->AccountURI);
     }
     return $account;
 }
예제 #4
0
파일: example.php 프로젝트: noahkim/kowop
print "ok, no more holds! let's capture it (for the full amount)\n";
$debit = $the_hold->capture();
print "hmm, ho much money do i have in escrow? it should equal the debit amount\n";
$marketplace = Balanced\Marketplace::mine();
if ($marketplace->in_escrow != 1500) {
    throw new Exception("1500 is not in escrow! This is wrong");
}
print "I have " . $marketplace->in_escrow . " in escrow!\n";
print "Cool. now let me refund the full amount";
$refund = $debit->refund();
print "ok, we have a merchant that's signing up, let's create an account for them first, let's create their bank account\n";
$bank_account = $marketplace->createBankAccount("Jack Q Merchant", "123123123", "123123123");
$identity = array("type" => "person", "name" => "Billy Jones", "street_address" => "801 High St", "postal_code" => "94301", "country" => "USA", "dob" => "1979-02", "phone_number" => "+16505551234");
$merchant = $marketplace->createMerchant('*****@*****.**', $identity, $bank_account->uri);
print "our buyer is interested in buying something for \$130\n";
$another_debit = $buyer->debit(13000, "MARKETPLACE.COM");
print "let's credit our merchant \$110\n";
$credit = $merchant->credit(11000, "Buyer purchase something on Marketplace.com");
print "let's assume the marketplace charges 15%, so it earned \$20\n";
$mp_credit = $marketplace->owner_account->credit(2000, "Commission from MARKETPLACE.COM");
print "ok, let's invalidate the card used so it cannot be used again\n";
$card->is_valid = false;
$card->save();
print "how do we look up an existing object from the URI?\n";
$the_buyer = Balanced\Account::get($buyer->uri);
print "we got the buyer " . $the_buyer->email_address . "\n";
$the_debit = Balanced\Debit::get($debit->uri);
print "we got the debit: " . $the_debit->uri . "\n";
$the_credit = Balanced\Credit::get($credit->uri);
print "we got the credit: " . $the_credit->uri . "\n";
print "and there you have it :)\n";
예제 #5
0
<?php

require __DIR__ . '/vendor/autoload.php';
Httpful\Bootstrap::init();
RESTful\Bootstrap::init();
Balanced\Bootstrap::init();
Balanced\Settings::$api_key = "ak-test-2eKlj1ZDfAcZSARMf3NMhBHywDej0avSY";
$payable_account = Balanced\Account::get("/accounts/AT3ogJE07IErLJYR510QO6sM");
$payable_account->credits->create(array("amount" => 1000, "appears_on_statement_as" => "ThingsCo", "description" => "A simple credit", "order" => "/orders/OR3vURGwVtqDnnkRS9fgH41G", "meta" => array("rating" => "8")));
예제 #6
0
파일: Payment.php 프로젝트: noahkim/kowop
 public static function ProcessPayments()
 {
     Yii::import('application.extensions.vendor.autoload', true);
     Httpful\Bootstrap::init();
     Balanced\Bootstrap::init();
     Balanced\Settings::$api_key = Yii::app()->params['balancedAPISecret'];
     //$pending = Payment::model()->findAll();
     $pending = Payment::model()->findAll(array('condition' => '(Status = ' . PaymentStatus::Scheduled . ')'));
     // AND ScheduledFor <= now()'));
     echo "Found " . count($pending) . " payments to process.\n\n";
     foreach ($pending as $payment) {
         try {
             $user = $payment->creditCard->user;
             $balancedAccount = null;
             if (isset($user->AccountURI) && $user->AccountURI != null) {
                 echo 'Account URI: ' . $user->AccountURI . "\n";
                 $balancedAccount = Balanced\Account::get($user->AccountURI);
             }
             // Convert to cents
             $amount = $payment->Amount * 100;
             $statementText = "Kowop.com";
             $meta = array("Payment_ID" => "{$payment->Payment_ID}");
             $description = "Charged \${$payment->Amount} for {$payment->experience->Name}";
             $balancedAccount->debit($amount, $statementText, $description, $meta, $payment->creditCard->URI);
             print_r($payment->attributes);
             echo str_repeat('-', 40) . "\n\n";
             $payment->Status = PaymentStatus::Processed;
             $payment->Processed = date('Y-m-d H:i:s');
             $payment->save();
         } catch (Exception $e) {
             Mail::Instance()->Alert("Error charging card", print_r($e));
             echo 'Error: ' . print_r($e, true) . "\n";
             $payment->Status = PaymentStatus::Error;
             $payment->save();
         }
     }
 }