Пример #1
0
 /**
  * @param \AppBundle\Entity\User $user
  * @param float $amount
  * @param string $description
  * @throws Exception
  * @return boolean
  */
 public function chargeUser(User $user, float $amount, $description)
 {
     $result = StripeCharge::create(["amount" => round($amount * 100), "currency" => "gbp", "customer" => $this->getCustomerId($user), "description" => $description]);
     $payment = new Payment();
     $payment->setUser($user);
     $payment->setSuccess(true);
     $payment->setDate(new \DateTime());
     $payment->setIntegration('stripe');
     $payment->setAmount($amount * 100);
     $payment->setReference($result->id);
     $this->persist($payment);
     $this->flush();
     if ($result->status != "succeeded") {
         throw new Exception("stripe payment failed");
     }
     return $result;
 }
 /**
  * @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;
 }