find() 공개 정적인 메소드

public static find ( string $id ) : Customer
$id string customer id
리턴 Customer
 /**
  * @param string $customer_id
  * @param string $plan_id
  * @param array $addOns
  * @param array $discounts
  * @param array $removeAddOns
  * @param array $removeDiscounts
  * @return bool | int
  * @throws Exception
  */
 public function createSubscription($customer_id, $plan_id, $addOns = [], $discounts = [], $removeAddOns = [], $removeDiscounts = [])
 {
     $customer = Braintree_Customer::find($customer_id);
     $the_token = null;
     if (!empty($customer)) {
         $the_token = $customer->paymentMethods[0]->token;
     } else {
         throw new Exception("Customer not found \n");
     }
     $formattedAddOns = [];
     foreach ($addOns as $addOn) {
         $formattedAddOns[] = ['inheritedFromId' => $addOn];
     }
     $formattedDiscounts = [];
     foreach ($discounts as $discount) {
         $formattedDiscounts[] = ['inheritedFromId' => $discount];
     }
     $result = Braintree_Subscription::create(['paymentMethodToken' => $the_token, 'planId' => $plan_id, 'addOns' => ['add' => $formattedAddOns, 'remove' => $removeAddOns], 'discounts' => ['add' => $formattedDiscounts, 'remove' => $removeDiscounts]]);
     if ($result->success) {
         return $result->subscription->id;
     } else {
         foreach ($result->errors->deepAll() as $error) {
             throw new Exception($error->code . ": " . $error->message . "\n");
         }
     }
     return false;
 }
예제 #2
0
 /**
  * @depends testCustomerCreate
  */
 public function testTokenPayment()
 {
     $customer = 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());
 }
예제 #3
0
 public 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 = Test\Helper::decodedClientToken(array("customerId" => $customerId, "options" => array("makeDefault" => true)));
     $authorizationFingerprint = json_decode($clientToken)->authorizationFingerprint;
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $response = $http->post('/client_api/v1/payment_methods/credit_cards.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
 /**
  * Get the Braintree customer for the user.
  *
  * @return \Braintree\Customer
  */
 public function asBraintreeCustomer()
 {
     return BraintreeCustomer::find($this->braintree_id);
 }
예제 #5
0
 public function testFromNonce()
 {
     $customer = Braintree\Customer::createNoValidate();
     $http = new HttpClientApi(Braintree\Configuration::$global);
     $nonce = $http->nonce_for_new_card(array("credit_card" => array("number" => "4009348888881881", "expirationMonth" => "11", "expirationYear" => "2099"), "customerId" => $customer->id));
     $creditCard = Braintree\CreditCard::fromNonce($nonce);
     $customer = Braintree\Customer::find($customer->id);
     $this->assertEquals($customer->creditCards[0], $creditCard);
 }
예제 #6
0
 public function testFindErrorsOnWhitespaceId()
 {
     $this->setExpectedException('InvalidArgumentException');
     Braintree\Customer::find('\\t');
 }
 /**
  * @param \AppBundle\Entity\User $user
  * @param float $amount
  * @return boolean
  */
 public function chargeUser(User $user, float $amount, $description)
 {
     //get braintree customer
     $customer = BraintreeCustomer::find($this->getCustomerId($user));
     $result = BraintreeTransaction::sale(['paymentMethodToken' => $customer->creditCards[0]->token, 'amount' => round($amount)]);
     $payment = new Payment();
     $payment->setUser($user);
     $payment->setSuccess(true);
     $payment->setDate(new \DateTime());
     $payment->setIntegration('braintree');
     $payment->setAmount($amount * 100);
     $payment->setReference($result->transaction->id);
     $this->persist($payment);
     $this->flush();
     return $result;
 }
예제 #8
0
 /**
  * @param string $idCustomer
  * @return Customer
  */
 public function findCustomer($idCustomer)
 {
     return Customer::find($idCustomer);
 }
예제 #9
0
 public function testFind_throwsExceptionIfNotFound()
 {
     $this->setExpectedException('Braintree\\Exception\\NotFound');
     Braintree\Customer::find("does-not-exist");
 }
예제 #10
0
 public function testSale_andStoreShippingAddressInVault()
 {
     $customer = Braintree\Customer::create(['firstName' => 'Mike', 'lastName' => 'Jones', 'company' => 'Jones Co.', 'email' => '*****@*****.**', 'phone' => '419.555.1234', 'fax' => '419.555.1235', 'website' => 'http://example.com'])->customer;
     $transaction = Braintree\Transaction::sale(['amount' => '100.00', 'customerId' => $customer->id, 'creditCard' => ['cardholderName' => 'The Cardholder', 'number' => Braintree\Test\CreditCardNumbers::$visa, 'expirationDate' => '05/12'], 'shipping' => ['firstName' => 'Darren', 'lastName' => 'Stevens'], 'options' => ['storeInVault' => true, 'storeShippingAddressInVault' => true]])->transaction;
     $customer = Braintree\Customer::find($customer->id);
     $this->assertEquals('Darren', $customer->addresses[0]->firstName);
     $this->assertEquals('Stevens', $customer->addresses[0]->lastName);
 }