Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 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()]);
     }
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 /**
  * 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()));
 }
Ejemplo n.º 5
0
 /**
  * @param $id
  *
  * @return object
  */
 public function getCustomerById($id)
 {
     try {
         $customer = \Braintree_Customer::find($id);
     } catch (\Braintree_Exception_NotFound $e) {
         return false;
     }
     return $customer;
 }
 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']);
         }
     }
 }
Ejemplo n.º 7
0
 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);
     }
 }
 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]'));
 }
 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);
 }
Ejemplo n.º 10
0
 /**
  * @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());
 }
 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));
 }
Ejemplo n.º 12
0
 /**
  * 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];
     }
 }
 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());
 }
Ejemplo n.º 14
0
 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;
 }
 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);
 }
Ejemplo n.º 16
0
 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);
         }
     }
 }
 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);
 }
 public function check($customer)
 {
     if (empty($customer)) {
         $customer = $this->_controller->currUser;
     }
     $firstName = $lastName = '';
     $name = explode(' ', $customer['User']['full_name']);
     if (count($name) > 0) {
         $firstName = array_shift($name);
         $lastName = implode(' ', $name);
     }
     $customerData = array('firstName' => $firstName, 'lastName' => $lastName, 'email' => $customer['User']['username'], 'phone' => $customer['User']['phone']);
     try {
         $_customer = Braintree_Customer::find('konstruktor-' . $customer['User']['id']);
         $_customer = Braintree_Customer::update('konstruktor-' . $customer['User']['id'], $customerData);
     } catch (Exception $e) {
         $_customer = Braintree_Customer::create(Hash::merge(array('id' => 'konstruktor-' . $customer['User']['id']), $customerData));
     }
     if ($_customer->success) {
         return $_customer->customer;
     }
     return array();
 }
Ejemplo n.º 19
0
<?php

require_once "PATH_TO_BRAINTREE/lib/Braintree.php";
Braintree_Configuration::environment("sandbox");
Braintree_Configuration::merchantId("your_merchant_id");
Braintree_Configuration::publicKey("your_public_key");
Braintree_Configuration::privateKey("your_private_key");
$result = Braintree_Customer::create(array("firstName" => $_POST["first_name"], "lastName" => $_POST["last_name"], "creditCard" => array("number" => $_POST["number"], "expirationMonth" => $_POST["month"], "expirationYear" => $_POST["year"], "cvv" => $_POST["cvv"], "billingAddress" => array("postalCode" => $_POST["postal_code"]))));
if ($result->success) {
    echo "Success! Customer ID: " . $result->customer->id;
} else {
    echo "Validation errors:<br/>";
    foreach ($result->errors->deepAll() as $error) {
        echo "- " . $error->message . "<br/>";
    }
}
 function test_rangeNode_amount()
 {
     $customer = Braintree_Customer::createNoValidate();
     $creditCard = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Jane Everywoman' . rand(), 'number' => '5105105105105100', 'expirationDate' => '05/12'))->creditCard;
     $t_1000 = Braintree_Transaction::saleNoValidate(array('amount' => '1000.00', 'paymentMethodToken' => $creditCard->token));
     $t_1500 = Braintree_Transaction::saleNoValidate(array('amount' => '1500.00', 'paymentMethodToken' => $creditCard->token));
     $t_1800 = Braintree_Transaction::saleNoValidate(array('amount' => '1800.00', 'paymentMethodToken' => $creditCard->token));
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::amount()->greaterThanOrEqualTo('1700')));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($t_1800->id, $collection->firstItem()->id);
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::amount()->lessThanOrEqualTo('1250')));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($t_1000->id, $collection->firstItem()->id);
     $collection = Braintree_Transaction::search(array(Braintree_TransactionSearch::creditCardCardholderName()->is($creditCard->cardholderName), Braintree_TransactionSearch::amount()->between('1100', '1600')));
     $this->assertEquals(1, $collection->maximumCount());
     $this->assertEquals($t_1500->id, $collection->firstItem()->id);
 }
Ejemplo n.º 21
0
 public function showBTCustomer()
 {
     $aCustomerId = $_GET["id_user"];
     $customer = Braintree_Customer::find($aCustomerId);
     pr($customer);
 }
Ejemplo n.º 22
0
 function testFindErrorsOnWhitespaceId()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree_Customer::find('\\t');
 }
Ejemplo n.º 23
0
 public function showBraintree()
 {
     try {
         $customer = Braintree_Customer::find('development_fruit_analytics_user_' . Auth::user()->id);
     } catch (Braintree_Exception_NotFound $e) {
         $result = Braintree_Customer::create(array('id' => 'development_fruit_analytics_user_' . Auth::user()->id, 'email' => Auth::user()->email));
         if ($result->success) {
             $customer = $result->customer;
         } else {
             // needs error handling
         }
     }
     $clientToken = Braintree_ClientToken::generate(array("customerId" => $customer->id));
     return View::make('dev.braintree', array('clientToken' => $clientToken));
 }
Ejemplo n.º 24
0
 /**
  *  factory method: returns an instance of Braintree_Customer
  *  to the requesting method, with populated properties
  *
  * @ignore
  * @return object instance of Braintree_Customer
  */
 public static function factory($attributes)
 {
     $instance = new Braintree_Customer();
     $instance->_initialize($attributes);
     return $instance;
 }
Ejemplo n.º 25
0
 public function createUpdateForm()
 {
     $user = $this->getDi()->auth->getUser(true);
     if (!$user) {
         throw new Am_Exception_InputError("You are not logged-in");
     }
     if (!($bid = $user->data()->get(Am_Paysystem_Braintree::CUSTOMER_ID))) {
         throw new Am_Exception_Paysystem('Customer braintree id is empty');
     }
     if (!($bt_member = Braintree_Customer::find($bid))) {
         throw new Am_Exception_Paysystem('Wrong customer braintree id');
     }
     if (!($token = $bt_member->creditCards[0]->token)) {
         throw new Am_Exception_Paysystem('Empty token for credit card');
     }
     $form = $this->plugin->createForm(Am_Form_CreditCard::USER_UPDATE);
     $form->setDataSources(array($this->_request, new HTML_QuickForm2_DataSource_Array($form->getDefaultValuesSalem($bt_member))));
     $form->addHidden('tr_data')->setValue(Braintree_TransparentRedirect::updateCreditCardData(array('redirectUrl' => $this->plugin->getPluginUrl(Am_Paysystem_Braintree::ACTION_UPDATE), 'paymentMethodToken' => $token, 'creditCard' => array('billingAddress' => array('options' => array('updateExisting' => true))))));
     return $form;
 }
Ejemplo n.º 26
0
 public function vaultCustomer()
 {
     $customerId = $this->customerDetails->id;
     if (empty($customerId)) {
         return null;
     } else {
         return Braintree_Customer::find($customerId);
     }
 }
Ejemplo n.º 27
0
 function testUnknownCardTypeIndicators()
 {
     $customer = Braintree_Customer::createNoValidate();
     $result = Braintree_CreditCard::create(array('customerId' => $customer->id, 'cardholderName' => 'Cardholder', 'number' => Braintree_CreditCardNumbers_CardTypeIndicators::UNKNOWN, 'expirationDate' => '05/12', 'options' => array('verifyCard' => true)));
     $this->assertEquals(Braintree_CreditCard::PREPAID_UNKNOWN, $result->creditCard->prepaid);
     $this->assertEquals(Braintree_CreditCard::DURBIN_REGULATED_UNKNOWN, $result->creditCard->durbinRegulated);
     $this->assertEquals(Braintree_CreditCard::PAYROLL_UNKNOWN, $result->creditCard->payroll);
     $this->assertEquals(Braintree_CreditCard::DEBIT_UNKNOWN, $result->creditCard->debit);
     $this->assertEquals(Braintree_CreditCard::HEALTHCARE_UNKNOWN, $result->creditCard->healthcare);
     $this->assertEquals(Braintree_CreditCard::COMMERCIAL_UNKNOWN, $result->creditCard->commercial);
     $this->assertEquals(Braintree_CreditCard::COUNTRY_OF_ISSUANCE_UNKNOWN, $result->creditCard->countryOfIssuance);
     $this->assertEquals(Braintree_CreditCard::ISSUING_BANK_UNKNOWN, $result->creditCard->issuingBank);
 }
Ejemplo n.º 28
0
 function updateCustomerViaTr($regularParams, $trParams)
 {
     Braintree_TestHelper::suppressDeprecationWarnings();
     $trData = Braintree_TransparentRedirect::updateCustomerData(array_merge($trParams, array("redirectUrl" => "http://www.example.com")));
     return Braintree_TestHelper::submitTrRequest(Braintree_Customer::updateCustomerUrl(), $regularParams, $trData);
 }
Ejemplo n.º 29
0
 /**
  * Delete a customer within Braintree
  *
  * @param $customerId
  *
  * @return \Braintree_Result_Successful
  */
 public function deleteCustomer($customerId)
 {
     try {
         return Braintree_Customer::delete($customerId);
     } catch (Exception $e) {
         Gene_Braintree_Model_Debug::log($e);
     }
     return false;
 }
 public function find($id)
 {
     switch ($this->context) {
         case 'customer':
             try {
                 return Braintree_Customer::find($id);
             } catch (Exception $e) {
                 return false;
             }
             break;
     }
 }