/**
  * @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;
 }
 /**
  * @Route("/paymentgateway", name="payment_gateway")
  */
 public function recievePaymentAction(Request $request)
 {
     if (0 === strpos($request->headers->get('Content-Type'), 'application/json')) {
         $payment = new Payment();
         $data = json_decode($request->getContent(), true);
         $base_string = $data['account_number'] . "=account_number&" . $data['amount'] . "=amount&" . $data['business_number'] . "=business_number&" . $data['currency'] . "=currency&" . $data['first_name'] . "=first_name&" . $data['internal_transaction_id'] . "=internal_transaction_id&" . $data['last_name'] . "=last_name&" . $data['middle_name'] . "=middle_name&" . $data['sender_phone'] . "=sender_phone&" . $data['service_name'] . "=service_name&" . $data['transaction_reference'] . "=transaction_reference&" . $data['transaction_timestamp'] . "=transaction_timestamp&" . $data['transaction_type'] . "=transaction_type";
         $hashed_value = hash_hmac("sha1", $base_string, "810c06caa57be23b9006e5e4499d1001f423e149");
         $hashed_expected = $data['signature'];
         if (self::hash_compareAction($hashed_value, $hashed_expected)) {
             $payment->setBusinessNumber($data['business_number']);
             $payment->setTransactionReference($data['transaction_reference']);
             $payment->setInternalTransactionId($data['internal_transaction_id']);
             $payment->setTransactionTimestamp($data['transaction_timestamp']);
             $payment->setTransactionType($data['transaction_type']);
             $payment->setAccountNumber($data['account_number']);
             $payment->setSenderPhone($data['sender_phone']);
             $payment->setFirstName($data['first_name']);
             $payment->setMiddleName($data['middle_name']);
             $payment->setLastName($data['last_name']);
             $payment->setAmount($data['amount']);
             $payment->setCurrency($data['currency']);
             $payment->setSignature($data['signature']);
             $em = $this->getDoctrine()->getManager();
             $em->persist($payment);
             $em->flush();
             return $response = new Response("Hashes match!");
         } else {
             //Audit
             $audit = new Audit();
             $audit->setUsername($data['sender_phone']);
             $audit->setName($data['first_name'] . " " . $data['last_name']);
             $audit->setFunctionType("Payment");
             $audit->setEventType("Hashes do not match!");
             $em = $this->getDoctrine()->getManager();
             $em->persist($audit);
             $em->flush();
             return $response = new Response("Hashes do not match!" . " " . "Base_String:" . $base_string . " " . "Generated signature:" . $hashed_value);
         }
     }
 }
 /**
  * @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;
 }
Example #4
0
 /**
  * Add payment
  *
  * @param \AppBundle\Entity\Payment $payment
  *
  * @return Auction
  */
 public function addPayment(\AppBundle\Entity\Payment $payment)
 {
     $this->payment[] = $payment;
     $payment->addAuction($this);
     return $this;
 }