本文整理汇总了PHP中Braintree_Customer::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Braintree_Customer::create方法的具体用法?PHP Braintree_Customer::create怎么用?PHP Braintree_Customer::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Braintree_Customer
的用法示例。
在下文中一共展示了Braintree_Customer::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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()]);
}
}
示例2: payment
public function payment()
{
$this->request->allowMethod('post');
if (!isset($this->request->data['amount']) || empty($this->request->data['amount'])) {
$this->redirect($this->referer());
}
$firstName = $lastName = '';
$name = explode(' ', $this->currUser['User']['full_name']);
if (count($name) > 0) {
$firstName = array_shift($name);
$lastName = implode(' ', $name);
}
$customerData = array('firstName' => $firstName, 'lastName' => $lastName, 'email' => $this->currUser['User']['username'], 'phone' => $this->currUser['User']['phone']);
try {
$customer = Braintree_Customer::find('konstruktor-' . $this->currUser['User']['id']);
$customer = Braintree_Customer::update('konstruktor-' . $this->currUser['User']['id'], $customerData);
} catch (Exception $e) {
$customer = Braintree_Customer::create(Hash::merge(array('id' => 'konstruktor-' . $this->currUser['User']['id']), $customerData));
}
if ($customer->success) {
$customer = $customer->customer;
} else {
throw new NotFoundException(__d('billing', 'Invalid billing group'));
}
$this->Session->write('Billing', array('amount' => $this->request->data['amount']));
$this->layout = 'profile_new';
$clientToken = Braintree_ClientToken::generate();
$this->set('clientToken', $clientToken);
$this->set('customer', $customer);
}
示例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: getCustomer
/**
* @param $data
*
* @return object
*/
private function getCustomer($data)
{
$customer = $this->getCustomerById($data['customerId']);
if ($customer == false) {
$customer = \Braintree_Customer::create(array('id' => $data['customerId'], 'firstName' => $data['firstName'], 'lastName' => $data['lastName'], 'email' => $data['email'], 'phone' => $data['phone']));
}
return $customer;
}
示例5: 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]'));
}
示例6: 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);
}
}
示例7: 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));
}
示例8: test_paypalAccountEmail
function test_paypalAccountEmail()
{
$nonce = Braintree_HttpClientApi::nonceForPayPalAccount(array('paypal_account' => array('consent_code' => 'PAYPAL_CONSENT_CODE')));
$customerId = 'UNIQUE_CUSTOMER_ID-' . strval(rand());
$customerResult = Braintree_Customer::create(array('paymentMethodNonce' => $nonce, 'id' => $customerId));
$this->assertTrue($customerResult->success);
$customer = $customerResult->customer;
$collection = Braintree_Customer::search(array(Braintree_CustomerSearch::id()->is($customer->id), Braintree_CustomerSearch::paypalAccountEmail()->is('jane.doe@example.com')));
$this->assertEquals(1, $collection->maximumCount());
$this->assertEquals($customer->id, $collection->firstItem()->id);
}
示例9: 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];
}
}
示例10: 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());
}
示例11: test_findDuplicateCardsGivenPaymentMethodToken
function test_findDuplicateCardsGivenPaymentMethodToken()
{
$creditCardRequest = array('number' => '63049580000009', 'expirationDate' => '05/2012');
$jim = Braintree_Customer::create(array('firstName' => 'Jim', 'creditCard' => $creditCardRequest))->customer;
$joe = Braintree_Customer::create(array('firstName' => 'Joe', 'creditCard' => $creditCardRequest))->customer;
$query = array(Braintree_CustomerSearch::paymentMethodTokenWithDuplicates()->is($jim->creditCards[0]->token));
$collection = Braintree_Customer::search($query);
$customerIds = array();
foreach ($collection as $customer) {
$customerIds[] = $customer->id;
}
$this->assertTrue(in_array($jim->id, $customerIds));
$this->assertTrue(in_array($joe->id, $customerIds));
}
示例12: 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;
}
示例13: createCustomer
public function createCustomer($data)
{
$result = Braintree_Customer::create($data);
echo "<pre>";
print_r($result);
echo "</pre>";
if ($result->success) {
return array('success' => 1, 'customer_id' => $result->customer->id);
} else {
$errors = $result->errors->deepAll();
if (count($errors) > 0 && ($errors[0]->code == 91609 || $errors[0]->message == 'Customer ID has already been taken.')) {
return array('success' => 1, 'customer_id' => $data['id']);
}
return array('success' => 0, 'validation_errors' => $errors);
}
}
示例14: subscribe
function subscribe($nonce, $info)
{
$customerResult;
$subscriptionResult;
$customerResult = Braintree_Customer::create(['firstName' => $info['fname'], 'lastName' => $info['lname'], 'email' => $info['email'], 'paymentMethodNonce' => $nonce]);
if (!$customerResult->success) {
return $this->processErrors('subscription', $customerResult->errors->deepAll());
}
$r = $customerResult->customer;
$a = $r->addresses[0];
$sql = 'INSERT INTO users (first_name, last_name, address, city, state, zip, braintree_customer_id, created_date, email) ';
$sql .= "VALUES ('" . $r->firstName . "','" . $r->lastName . "','" . $a->streetAddress . "','" . $a->locality . "','" . $a->region . "','" . $a->postalCode . "','" . $r->id . "', now(),'" . $r->email . "');";
$info['userId'] = MysqlAccess::insert($sql);
$subscriptionResult = Braintree_Subscription::create(['paymentMethodToken' => $customerResult->customer->paymentMethods[0]->token, 'planId' => 'donation', 'price' => $info['amount']]);
if (!isset($subscriptionResult->subscription) || !$subscriptionResult->subscription) {
return $this->processErrors('subscription', $subscriptionResult->errors->deepAll());
}
return $this->retrieveSubscriptionResults($subscriptionResult->success, $subscriptionResult->subscription, $info);
}
示例15: test_GatewayRespectsMakeDefault
function test_GatewayRespectsMakeDefault()
{
$result = Braintree_Customer::create();
$this->assertTrue($result->success);
$customerId = $result->customer->id;
$result = Braintree_CreditCard::create(array('customerId' => $customerId, 'number' => '4111111111111111', 'expirationDate' => '11/2099'));
$this->assertTrue($result->success);
$clientToken = Braintree_ClientToken::generate(array("customerId" => $customerId, "options" => array("makeDefault" => true)));
$authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
$response = Braintree_HttpClientApi::post('/client_api/nonces.json', json_encode(array("credit_card" => array("number" => "4242424242424242", "expirationDate" => "11/2099"), "authorization_fingerprint" => $authorizationFingerprint, "shared_customer_identifier" => "fake_identifier", "shared_customer_identifier_type" => "testing")));
$this->assertEquals(201, $response["status"]);
$customer = Braintree_Customer::find($customerId);
$this->assertEquals(2, count($customer->creditCards));
foreach ($customer->creditCards as $creditCard) {
if ($creditCard->last4 == "4242") {
$this->assertTrue($creditCard->default);
}
}
}