本文整理汇总了PHP中Braintree_Customer类的典型用法代码示例。如果您正苦于以下问题:PHP Braintree_Customer类的具体用法?PHP Braintree_Customer怎么用?PHP Braintree_Customer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Braintree_Customer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCustomerCards
/**
* Returns customer credit cards if applicable
*
* @return Braintree_Customer | boolean
*/
public function getCustomerCards()
{
$session = Mage::getSingleton('adminhtml/session_quote');
$applicableCards = array();
if (Mage::getStoreConfig(self::CONFIG_PATH_VAULT, $session->getStoreId())) {
$storedCards = false;
if ($session->getCustomerId()) {
$customerId = Mage::helper('braintree_payments')->generateCustomerId($session->getCustomerId(), $session->getQuote()->getCustomerEmail());
try {
$storedCards = Braintree_Customer::find($customerId)->creditCards;
} catch (Braintree_Exception $e) {
Mage::logException($e);
}
}
if ($storedCards) {
$country = $session->getQuote()->getBillingAddress()->getCountryId();
$types = Mage::getModel('braintree_payments/creditcard')->getApplicableCardTypes($country);
$applicableCards = array();
foreach ($storedCards as $card) {
if (in_array(Mage::helper('braintree_payments')->getCcTypeCodeByName($card->cardType), $types)) {
$applicableCards[] = $card;
}
}
}
}
return $applicableCards;
}
示例2: braintree
function braintree($data)
{
foreach ($data as $k => $v) {
${$k} = $v;
}
try {
include_once 'config.braintree.php';
$customer = Braintree_Customer::create(['firstName' => $first_name, 'lastName' => $last_name]);
if (!isset($nonce) || empty($nonce)) {
throw new Exception("An unknown error has occurred");
}
if ($customer->success) {
$transaction = Braintree_Transaction::sale(['amount' => $price, 'customerId' => $customer->customer->id, 'paymentMethodNonce' => $nonce]);
if ($transaction->success) {
$this->save($data, __FUNCTION__, $transaction->transaction, 1);
return json_encode(["status" => true, "msg" => sprintf("Your payment has been %s", $transaction->transaction->status)]);
} else {
throw new Exception($transaction->message);
}
}
} catch (Exception $e) {
$this->save($data, __FUNCTION__, (string) $e, 0);
return json_encode(["status" => false, "msg" => $e->getMessage()]);
}
}
示例3: _createCustomer
private function _createCustomer($CustomerData)
{
$name = explode(' ', $CustomerData['Order']['customer_name']);
$firstName = $name[0];
$lastName = $name[1];
$customerDetails = Braintree_Customer::create(['firstName' => $firstName, 'lastName' => $lastName]);
return $customerDetails->customer->id;
}
示例4: init
/**
* create signatures for different call types
* @ignore
*/
public static function init()
{
self::$_createCustomerSignature = array(self::$_transparentRedirectKeys, array('customer' => Braintree_Customer::createSignature()));
self::$_updateCustomerSignature = array(self::$_transparentRedirectKeys, 'customerId', array('customer' => Braintree_Customer::updateSignature()));
self::$_transactionSignature = array(self::$_transparentRedirectKeys, array('transaction' => Braintree_Transaction::createSignature()));
self::$_createCreditCardSignature = array(self::$_transparentRedirectKeys, array('creditCard' => Braintree_CreditCard::createSignature()));
self::$_updateCreditCardSignature = array(self::$_transparentRedirectKeys, 'paymentMethodToken', array('creditCard' => Braintree_CreditCard::updateSignature()));
}
示例5: getCustomerById
/**
* @param $id
*
* @return object
*/
public function getCustomerById($id)
{
try {
$customer = \Braintree_Customer::find($id);
} catch (\Braintree_Exception_NotFound $e) {
return false;
}
return $customer;
}
示例6: testUpdateSignature_doesNotAlterOptionsInCreditCardUpdateSignature
function testUpdateSignature_doesNotAlterOptionsInCreditCardUpdateSignature()
{
Braintree_Customer::updateSignature();
foreach (Braintree_CreditCard::updateSignature() as $key => $value) {
if (is_array($value) and array_key_exists('options', $value)) {
$this->assertEquals(array('makeDefault', 'verificationMerchantAccountId', 'verifyCard'), $value['options']);
}
}
}
示例7: saveCustomer
public function saveCustomer()
{
$result = Braintree_Customer::create($this->options['customer']);
if ($result->success) {
return array('status' => true, 'result' => $result);
} else {
return array('status' => false, 'result' => $result);
}
}
示例8: testValueForHtmlField
function testValueForHtmlField()
{
$result = Braintree_Customer::create(array('email' => 'invalid-email', 'creditCard' => array('number' => 'invalid-number', 'expirationDate' => 'invalid-exp', 'billingAddress' => array('countryName' => 'invalid-country'))));
$this->assertEquals(false, $result->success);
$this->assertEquals('invalid-email', $result->valueForHtmlField('customer[email]'));
$this->assertEquals('', $result->valueForHtmlField('customer[credit_card][number]'));
$this->assertEquals('invalid-exp', $result->valueForHtmlField('customer[credit_card][expiration_date]'));
$this->assertEquals('invalid-country', $result->valueForHtmlField('customer[credit_card][billing_address][country_name]'));
}
示例9: testCreate_fromPaymentMethodToken
function testCreate_fromPaymentMethodToken()
{
$customer = Braintree_Customer::createNoValidate();
$card = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => '5105105105105100', 'expirationDate' => '05/12'))->creditCard;
$result = Braintree_PaymentMethodNonce::create($card->token);
$this->assertTrue($result->success);
$this->assertNotNull($result->paymentMethodNonce);
$this->assertNotNull($result->paymentMethodNonce->nonce);
}
示例10: testTokenPayment
/**
* @depends testCustomerCreate
*/
public function testTokenPayment()
{
$customer = \Braintree_Customer::find(self::$customer->id);
$this->assertInstanceOf('\\Braintree_Customer', $customer);
$this->assertArrayHasKey(0, $customer->paymentMethods());
$model = new BraintreeForm();
$model->setScenario('saleFromVault');
$this->assertTrue($model->load(['amount' => rand(1, 200), 'paymentMethodToken' => $customer->paymentMethods()[0]->token], ''));
$this->assertNotFalse($model->send());
}
示例11: test_deepAll_givesAllErrorsDeeply
function test_deepAll_givesAllErrorsDeeply()
{
$result = Braintree_Customer::create(array('email' => 'invalid', 'creditCard' => array('number' => '1234123412341234', 'expirationDate' => 'invalid', 'billingAddress' => array('countryName' => 'invalid'))));
$expectedErrors = array(Braintree_Error_Codes::CUSTOMER_EMAIL_IS_INVALID, Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID, Braintree_Error_Codes::CREDIT_CARD_NUMBER_IS_INVALID, Braintree_Error_Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED);
$actualErrors = $result->errors->deepAll();
$this->assertEquals($expectedErrors, self::mapValidationErrorsToCodes($actualErrors));
$expectedErrors = array(Braintree_Error_Codes::CREDIT_CARD_EXPIRATION_DATE_IS_INVALID, Braintree_Error_Codes::CREDIT_CARD_NUMBER_IS_INVALID, Braintree_Error_Codes::ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED);
$actualErrors = $result->errors->forKey('customer')->forKey('creditCard')->deepAll();
$this->assertEquals($expectedErrors, self::mapValidationErrorsToCodes($actualErrors));
}
示例12: saveCustomer
/**
* This save customer to braintree and returns result array
* @return array
*/
public function saveCustomer()
{
if (isset($this->options['customerId'])) {
$this->options['customer']['id'] = $this->options['customerId'];
}
$result = \Braintree_Customer::create($this->options['customer']);
if ($result->success) {
return ['status' => true, 'result' => $result];
} else {
return ['status' => false, 'result' => $result];
}
}
示例13: test_multipleValueNode_creditCardType
function test_multipleValueNode_creditCardType()
{
$result = Braintree_Customer::create(array('creditCard' => array('cardholderName' => "Joe Smith", 'number' => "4000111111111115", 'expirationDate' => "12/2016", 'options' => array('verifyCard' => true))));
$creditCardVerification = $result->creditCardVerification;
$collection = Braintree_CreditCardVerification::search(array(Braintree_CreditCardVerificationSearch::id()->is($creditCardVerification->id), Braintree_CreditCardVerificationSearch::creditCardCardType()->is($creditCardVerification->creditCard['cardType'])));
$this->assertEquals(1, $collection->maximumCount());
$this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
$collection = Braintree_CreditCardVerification::search(array(Braintree_CreditCardVerificationSearch::id()->is($creditCardVerification->id), Braintree_CreditCardVerificationSearch::creditCardCardType()->in(array($creditCardVerification->creditCard['cardType'], Braintree_CreditCard::CHINA_UNION_PAY))));
$this->assertEquals(1, $collection->maximumCount());
$this->assertEquals($creditCardVerification->id, $collection->firstItem()->id);
$collection = Braintree_CreditCardVerification::search(array(Braintree_CreditCardVerificationSearch::id()->is($creditCardVerification->id), Braintree_CreditCardVerificationSearch::creditCardCardType()->is(Braintree_CreditCard::CHINA_UNION_PAY)));
$this->assertEquals(0, $collection->maximumCount());
}
示例14: create_customer_with_card
function create_customer_with_card($card_info)
{
$names = explode(' ', $card_info['cardholderName']);
$data['firstName'] = isset($names[0]) ? $names[0] : NULL;
$data['lastName'] = isset($names[1]) ? $names[1] : NULL;
$data['creditCard'] = $card_info;
//var_dump($data);
$result = Braintree_Customer::create($data);
if ($result->success === true) {
return array('cust_id' => $result->customer->id, 'card_token' => $result->customer->creditCards[0]->token);
}
$this->_parse_errors($result);
return false;
}
示例15: test_createdAt
function test_createdAt()
{
$customer = Braintree_Customer::createNoValidate();
$past = clone $customer->createdAt;
$past->modify("-1 hour");
$future = clone $customer->createdAt;
$future->modify("+1 hour");
$collection = Braintree_Customer::search(array(Braintree_CustomerSearch::id()->is($customer->id), Braintree_CustomerSearch::createdAt()->between($past, $future)));
$this->assertEquals(1, $collection->maximumCount());
$this->assertEquals($customer->id, $collection->firstItem()->id);
$collection = Braintree_Customer::search(array(Braintree_CustomerSearch::id()->is($customer->id), Braintree_CustomerSearch::createdAt()->lessThanOrEqualTo($future)));
$this->assertEquals(1, $collection->maximumCount());
$this->assertEquals($customer->id, $collection->firstItem()->id);
$collection = Braintree_Customer::search(array(Braintree_CustomerSearch::id()->is($customer->id), Braintree_CustomerSearch::createdAt()->greaterThanOrEqualTo($past)));
$this->assertEquals(1, $collection->maximumCount());
$this->assertEquals($customer->id, $collection->firstItem()->id);
}