Ejemplo n.º 1
0
 public function chargeCard(Card $card, Customer $customer, $amount, $statement = null, $description = null)
 {
     if (!$customer->getBalancedUri()) {
         //create customer if need
         $this->paymentManager->createCustomer($customer);
     }
     if (!$card->getBalancedUri()) {
         //create card
         $this->paymentManager->createCard($card, $customer);
     }
     //save transaction data
     $payment = new PaymentHistory();
     $payment->setFromUser($customer);
     $payment->setAmount($amount / 100);
     if ($amount > 0) {
         $debitData = $this->paymentManager->debit($card, $customer, $amount, $statement, $description);
         $payment->setReference($debitData->id);
         $payment->setData(json_encode($debitData));
         $payment->setState($debitData->status);
         $payment->setBalancedUri($debitData->href);
     } else {
         $payment->setData(json_encode(['created_at' => (new \DateTime('now'))->format('d-m-Y H:i:s'), 'amount' => 0]));
         $payment->setState(PaymentHistory::STATE_SUCCESS);
     }
     $this->entityManager->persist($payment);
     $this->entityManager->flush($payment);
     return $payment;
 }
 public function setFromUser($fromUser)
 {
     $this->__load();
     return parent::setFromUser($fromUser);
 }
Ejemplo n.º 3
0
 private function saveToPaymentHistory($debitData, Customer $from, Customer $to = null, $amount, $question_id = null, $orderId = null)
 {
     $payment = new PaymentHistory();
     $payment->setReference($debitData->id);
     $payment->setData(json_encode($debitData));
     $payment->setFromUser($from);
     $payment->setToUser($to);
     $payment->setState($debitData->status);
     $payment->setAmount($amount);
     $payment->setBalancedUri($debitData->href);
     $payment->setQuestionId($question_id);
     $payment->setOrderId($orderId);
     $this->em->persist($payment);
     $this->em->flush($payment);
     return $payment;
 }