function testSale_createsASaleUsingGivenToken()
 {
     $customer = Braintree_Customer::createNoValidate(array('creditCard' => array('number' => '5105105105105100', 'expirationDate' => '05/12')));
     $creditCard = $customer->creditCards[0];
     $result = Braintree_CreditCard::sale($creditCard->token, array('amount' => '100.00'));
     $this->assertTrue($result->success);
     $this->assertEquals('100.00', $result->transaction->amount);
     $this->assertEquals($customer->id, $result->transaction->customerDetails->id);
     $this->assertEquals($creditCard->token, $result->transaction->creditCardDetails->token);
 }
Beispiel #2
0
 public function executePaypal()
 {
     $this->user = $this->getUser()->getRaykuUser();
     $this->userId = $this->user->getId();
     if (sfWebRequest::POST === $this->getRequest()->getMethod() && $this->hasRequestParameter('submit_card')) {
         $expiration = substr($this->getRequestParameter('expiry_date'), 0, 2) . '/' . substr($this->getRequestParameter('expiry_date'), -2);
         require_once $_SERVER['DOCUMENT_ROOT'] . '/braintree_environment.php';
         $result = Braintree_Customer::create(array('firstName' => $this->user->getName(), 'lastName' => '', 'creditCard' => array('cardholderName' => $this->getRequestParameter('realname'), 'number' => $this->getRequestParameter('credit_card'), 'cvv' => $this->getRequestParameter('cvv'), 'expirationDate' => $expiration, 'options' => array('verifyCard' => true))));
         error_log($result->customer->creditCards[0]->token, 0);
         if (!$result->success) {
             $this->error = 'Your credit card is invalid.';
             //return sfView::SUCCESS;
         } else {
             //should only save last 4 digit
             $this->user->setCreditCard(substr($this->getRequestParameter('credit_card'), -4));
             $this->user->setCreditCardToken($result->customer->creditCards[0]->token);
             $this->user->save();
             //return sfView::SUCCESS;
         }
     }
     if (sfWebRequest::POST === $this->getRequest()->getMethod() && $this->hasRequestParameter('pay_balance')) {
         $this->points = $this->user->getPoints();
         $this->token = $this->user->getCreditCardToken();
         if ($this->points < 0) {
             $amount = '' . $this->points * -1;
             require_once $_SERVER['DOCUMENT_ROOT'] . '/braintree_environment.php';
             $result = Braintree_CreditCard::sale($this->token, array('amount' => $amount, 'credit_card' => array()));
             // error_log($result->customer->creditCards[0]->token, 0);
             if (!$result->success) {
                 //error_log("invalid", 0);
                 $this->error = 'Your credit card is invalid.';
             } else {
                 //should pay all balance
                 $this->user->setPoints(0);
                 $this->user->save();
             }
         }
     }
     $this->token = $this->user->getCreditCardToken();
     $this->cardNum = $this->user->getCreditCard();
     return sfView::SUCCESS;
 }