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 unstoreCustomer(Customer $customerEntity)
 {
     $customer = $this->balancedPaymentCalls->getCustomer($customerEntity->getBalancedUri());
     $customer->unstore();
 }