예제 #1
0
 public static function nonceForPayPalAccount($options)
 {
     $clientToken = json_decode(Braintree_TestHelper::decodedClientToken());
     $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
     $response = Braintree_HttpClientApi::post('/client_api/v1/payment_methods/paypal_accounts.json', json_encode($options));
     if ($response["status"] == 201 || $response["status"] == 202) {
         $body = json_decode($response["body"], true);
         return $body["paypalAccounts"][0]["nonce"];
     } else {
         throw new Exception(var_dump($response));
     }
 }
예제 #2
0
 public static function nonce_for_new_card($options)
 {
     $clientTokenOptions = array();
     if (array_key_exists("customerId", $options)) {
         $clientTokenOptions["customerId"] = $options["customerId"];
         unset($options["customerId"]);
     }
     $clientToken = json_decode(Braintree_ClientToken::generate($clientTokenOptions));
     $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
     $options["shared_customer_identifier"] = "fake_identifier_" . rand();
     $options["shared_customer_identifier_type"] = "testing";
     $response = Braintree_HttpClientApi::post('/client_api/nonces.json', json_encode($options));
     if ($response["status"] != 201) {
         throw new Exception(var_dump($response));
     } else {
         $body = json_decode($response["body"]);
         return $body->nonce;
     }
 }
예제 #3
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);
         }
     }
 }
예제 #4
0
 function testFromNonce_ReturnsErrorWhenNonceIsLocked()
 {
     $customer = Braintree_Customer::createNoValidate();
     $clientTokenOptions = array();
     $clientToken = json_decode(Braintree_TestHelper::decodedClientToken($clientTokenOptions));
     $sharedCustomerIdentifier = "fake_identifier_" . rand();
     $options = array("credit_card" => array("number" => "4009348888881881", "expirationMonth" => "11", "expirationYear" => "2099"), "share" => true);
     $options["authorization_fingerprint"] = $clientToken->authorizationFingerprint;
     $options["shared_customer_identifier"] = $sharedCustomerIdentifier;
     $options["shared_customer_identifier_type"] = "testing";
     $response = Braintree_HttpClientApi::post('/client_api/v1/payment_methods/credit_cards.json', json_encode($options));
     $this->assertEquals(201, $response["status"]);
     unset($options["credit_card"]);
     $response = Braintree_HttpClientApi::get_cards($options);
     $body = json_decode($response["body"]);
     $nonce = $body->paymentMethods[0]->nonce;
     $this->setExpectedException('Braintree_Exception_NotFound', "locked");
     Braintree_CreditCard::fromNonce($nonce);
 }