我们如何使用平衡付款处理付款?
当使用下面的代码,我得到一个错误:我们如何使用平衡付款处理付款?
$page = $_SERVER['REQUEST_URI'];
Settings::$api_key = $API_KEY_SECRET;
$marketplace = Marketplace::mine();
if ($page == '/')
{
// do nothing
}
elseif ($page == '/buyer') {
if (isset($_POST['uri']) and isset($_POST['email_address'])) {
// create in balanced
$email_address = $_POST['email_address'];
$card_uri = $_POST['uri'];
try {
echo create_buyer($email_address, $card_uri)->uri;
return;
} catch (Exception $e) {
echo $e->getMessage();
return;
}
}
}
function create_buyer($email_address, $card_uri) {
$marketplace = Marketplace::mine();
try {
# new buyer
$buyer = $marketplace->createBuyer(
$email_address,
$card_uri);
}
catch (Exception $e) {
if ($e->category_code == 'duplicate-email-address') {
# oops, account for $email_address already exists so just add the card
$buyer = $marketplace
->accounts
->query()
->filter(Account::$f->email_address->eq($email_address))
->one();
$buyer->addCard($card_uri);
}
else {
throw $e;
}
}
return $buyer;
}
我收到此错误:
Fatal error: Uncaught exception 'NoResultFound' in /var/www/html/site/balancepayment/Balanced/Core/Query.php:134 Stack trace: #0 /var/www/html/site/balancepayment/Balanced/Marketplace.php(48): Query->one() #1 /var/www/html/site/balancepayment/index.php(16): Marketplace::mine() #2 {main} thrown in /var/www/html/site/balancepayment/Balanced/Core/Query.php on line 134
你有没有在本教程的第一步中创建一个市场怎么样?
https://www.balancedpayments.com/docs/php#quickstart
Balanced\Settings::$api_key = $key->secret;
$marketplace = new Balanced\Marketplace();
$marketplace->save();
行,所以就在代码示例的顶部有评论
/**
* Represents a marketplace.
*
* To get started you create an api key and then create a marketplace:
*
但是,由于某种原因,我的开发并不apear要按照顺序方向。
BalancedPayments, 我不是一个编码器,你能否确认我的开发者没有正确遵循正确的顺序。看起来他们正试图跳过第2步....
<?php
/**
* Represents a marketplace.
*
* To get started you create an api key and then create a marketplace:
*
* <code>
* $api_key = new \Balanced\APIKey();
* $api_key->save();
* $secret = $api_key->secret // better save this somewhere
* print $secret;
* \Balanced\Settings::$api_key = $secret;
*
* $marketplace = new \Balanced\Marketplace();
* $marketplace->save();
* var_dump($marketplace);
* </code>
*
* Each api key is uniquely assocaited with an api key so once you've created a
* marketplace:
*
* <code>
* \Balanced\Settings::$api_key = $secret;
* $marketplace = \Balanced\Marketplace::mine(); // this is the marketplace associated with $secret
* </code>
*/
class Marketplace extends Resource
{
protected static $_uri_spec = null;
public static function init()
{
self::$_uri_spec = new URISpec('marketplaces', 'id', '/v1');
self::$_registry->add(get_called_class());
}
/**
* Get the marketplace associated with the currently configured
* \Balanced\Settings::$api_key.
*
* @throws \Balanced\Exceptions\NoResult
* @return \Balanced\Marketplace
*/
public static function mine()
{
return self::query()->one();
}
/**
* Create a card. These can later be associated with an account using
* \Balanced\Account->addCard or \Balanced\Marketplace->createBuyer.
*
* @param string street_address Street address. Use null if there is no address for the card.
* @param string city City. Use null if there is no address for the card.
* @param string postal_code Postal code. Use null if there is no address for the card.
* @param string name Name as it appears on the card.
* @param string card_number Card number.
* @param string security_code Card security code. Use null if it is no available.
* @param int expiration_month Expiration month.
* @param int expiration_year Expiration year.
*
* @return \Balanced\Card
*/
public function createCard(
$street_address,
$city,
$region,
$postal_code,
$name,
$card_number,
$security_code,
$expiration_month,
$expiration_year)
{
if ($region != null && strlen($region) > 0) {
trigger_error("The region parameter will be deprecated in the next minor version of balanced-php", E_USER_NOTICE);
}
return $this->cards->create(array(
'street_address' => $street_address,
'city' => $city,
'region' => $region,
'postal_code' => $postal_code,
'name' => $name,
'card_number' => $card_number,
'security_code' => $security_code,
'expiration_month' => $expiration_month,
'expiration_year' => $expiration_year
));
}
/**
* Create a bank account. These can later be associated with an account
* using \Balanced\Account->addBankAccount.
*
* @param string name Name of the account holder.
* @param string account_number Account number.
* @param string bank_code Bank code or routing number.
*
* @return \Balanced\BankAccount
*/
public function createBankAccount(
$name,
$account_number,
$bank_code
)
{
return $this->bank_accounts->create(array(
'name' => $name,
'account_number' => $account_number,
'bank_code' => $bank_code,
));
}
/**
* Create a role-less account. You can later turn this into a buyer by
* adding a funding source (e.g a card) or a merchant using
* \Balanced\Account->promoteToMerchant.
*
* @param string email_address Email address. There can only be one account with this email address.
* @param array[string]string meta Optional metadata to associate with the account.
*
* @return \Balanced\Account
*/
public function createAccount($email_address, $meta = null)
{
return $this->accounts->create(array(
'email_address' => $email_address,
'meta' => $meta,
));
}
/**
* Create a buyer account.
*
* @param string email_address Email address. There can only be one account with this email address.
* @param string card_uri URI referencing a card to associate with the account.
* @param array[string]string meta Optional metadata to associate with the account.
*
* @return \Balanced\Account
*/
public function createBuyer($email_address, $card_uri, $meta = null)
{
return $this->accounts->create(array(
'email_address' => $email_address,
'card_uri' => $card_uri,
'meta' => $meta,
));
}
/**
* Create a merchant account.
*
* Unlike buyers the identity of a merchant must be established before
* the account can function as a merchant (i.e. be credited). A merchant
* can be either a person or a business. Either way that information is
* represented as an associative array and passed as the merchant parameter
* when creating the merchant account.
*
* For a person the array looks like this:
*
* <code>
* array(
* 'type' => 'person',
* 'name' => 'William James',
* 'tax_id' => '393-48-3992',
* 'street_address' => '167 West 74th Street',
* 'postal_code' => '10023',
* 'dob' => '1842-01-01',
* 'phone_number' => '+16505551234',
* 'country_code' => 'USA'
* )
* </code>
*
* For a business the array looks like this:
*
* <code>
* array(
* 'type' => 'business',
* 'name' => 'Levain Bakery',
* 'tax_id' => '253912384',
* 'street_address' => '167 West 74th Street',
* 'postal_code' => '10023',
* 'phone_number' => '+16505551234',
* 'country_code' => 'USA',
* 'person' => array(
* 'name' => 'William James',
* 'tax_id' => '393483992',
* 'street_address' => '167 West 74th Street',
* 'postal_code' => '10023',
* 'dob' => '1842-01-01',
* 'phone_number' => '+16505551234',
* 'country_code' => 'USA',
* )
* )
* </code>
*
* In some cases the identity of the merchant, person or business, cannot
* be verified in which case a \Balanced\Exceptions\HTTPError is thrown:
*
* <code>
* $identity = array(
* 'type' => 'business',
* 'name' => 'Levain Bakery',
* 'tax_id' => '253912384',
* 'street_address' => '167 West 74th Street',
* 'postal_code' => '10023',
* 'phone_number' => '+16505551234',
* 'country_code' => 'USA',
* 'person' => array(
* 'name' => 'William James',
* 'tax_id' => '393483992',
* 'street_address' => '167 West 74th Street',
* 'postal_code' => '10023',
* 'dob' => '1842-01-01',
* 'phone_number' => '+16505551234',
* 'country_code' => 'USA',
* ),
* );
*
* try {
* $merchant = \Balanced\Marketplace::mine()->createMerchant(
* '[email protected]',
* $identity,
* );
* catch (\Balanced\Exceptions\HTTPError $e) {
* if ($e->code != 300) {
* throw $e;
* }
* print e->response->header['Location'] // this is where merchant must signup
* }
* </code>
*
* Once the merchant has completed signup you can use the resulting URI to
* create an account for them on your marketplace:
*
* <code>
* $merchant = self::$marketplace->createMerchant(
* '[email protected]',
* null,
* null,
* $merchant_uri
* );
* </coe>
*
* @param string email_address Email address. There can only be one account with this email address.
* @param array[string]mixed merchant Associative array describing the merchants identity.
* @param string $bank_account_uri Optional URI referencing a bank account to associate with this account.
* @param string $merchant_uri URI of a merchant created via the redirection sign-up flow.
* @param string $name Optional name of the merchant.
* @param array[string]string meta Optional metadata to associate with the account.
*
* @return \Balanced\Account
*/
public function createMerchant(
$email_address,
$merchant = null,
$bank_account_uri = null,
$merchant_uri = null,
$name = null,
$meta = null
)
{
return $this->accounts->create(array(
'email_address' => $email_address,
'merchant' => $merchant,
'merchant_uri' => $merchant_uri,
'bank_account_uri' => $bank_account_uri,
'name' => $name,
'meta' => $meta,
));
}
}
我已经创建了一个平衡收支的定制库,它是在github https://github.com/yousafsyed/balancedpayments
这里availble的是使用
的例子require ("balancedpayments.php");
$config = array(
"apikey" => "ak-test-23923840140fisdfjsodfjd9fjks22sdww", // set your api key secret
"payment_description" => " Charging the card", // set the payment description
"statement_appear_as" => "Example Company"// set the statement
);
Balancedpayments::config($config); // pass the config array
/**
* Create customer example
* */
$userdata = array(
"name" => "yousaf",
"email" => "[email protected]",
"adddres" => "NY street 1",
"meta[user_id]" => "123"
);
Balancedpayments::create_user($userdata);
对于多个使用实施例参见在github的例子 https://github.com/yousafsyed/balancedpayments#usage
是的..我已经完成了..我给你我的代码 – Debashish 2012-08-10 06:04:21
你能帮我吗如何处理付款后创建市场... – Debashish 2012-08-10 06:18:54
Debashish - 你看了examples.php文件在图书馆 - https://github.com/balanced/balanced-php/blob/master/example/example.php - 请参阅第43行以了解如何创建付款。 – mjallday 2012-08-10 15:11:03