コード例 #1
0
 /**
  * @return array
  */
 public function getFilters()
 {
     return [new \Twig_SimpleFilter('formatCurrency', function ($money) {
         if (!$money instanceof Money && is_int($money)) {
             $money = new Money($money, $this->currency);
         }
         return $this->formatter->format($money);
     })];
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     /** @var Payment $payment */
     $payment = $request->getModel();
     if ($payment->getDetails()) {
         return;
     }
     $invoice = $payment->getInvoice();
     $details = [];
     $details['PAYMENTREQUEST_0_INVNUM'] = $invoice->getId() . '-' . $payment->getId();
     $details['PAYMENTREQUEST_0_CURRENCYCODE'] = $payment->getCurrencyCode();
     $details['PAYMENTREQUEST_0_AMT'] = number_format($this->formatter->toFloat($invoice->getTotal()), 2);
     $details['PAYMENTREQUEST_0_ITEMAMT'] = number_format($this->formatter->toFloat($invoice->getTotal()), 2);
     $counter = 0;
     foreach ($invoice->getItems() as $item) {
         /* @var \CSBill\InvoiceBundle\Entity\Item $item */
         $details['L_PAYMENTREQUEST_0_NAME' . $counter] = $item->getDescription();
         $details['L_PAYMENTREQUEST_0_AMT' . $counter] = number_format($this->formatter->toFloat($item->getPrice()), 2);
         $details['L_PAYMENTREQUEST_0_QTY' . $counter] = $item->getQty();
         ++$counter;
     }
     if (null !== $invoice->getDiscount()) {
         $discount = $invoice->getBaseTotal()->multiply($invoice->getDiscount());
         $details['L_PAYMENTREQUEST_0_NAME' . $counter] = 'Discount';
         $details['L_PAYMENTREQUEST_0_AMT' . $counter] = '-' . number_format($this->formatter->toFloat($discount), 2);
         $details['L_PAYMENTREQUEST_0_QTY' . $counter] = 1;
     }
     if (null !== ($tax = $invoice->getTax())) {
         $details['L_PAYMENTREQUEST_0_NAME' . $counter] = 'Tax Total';
         $details['L_PAYMENTREQUEST_0_AMT' . $counter] = number_format($this->formatter->toFloat($tax), 2);
         $details['L_PAYMENTREQUEST_0_QTY' . $counter] = 1;
     }
     /*$notifyUrl = $this->tokenFactory->createNotifyToken(
                 $request->getToken()->getGatewayName(),
                 $payment
             )->getTargetUrl();
     
             $details['PAYMENTREQUEST_0_NOTIFYURL'] = $notifyUrl;*/
     $payment->setDetails($details);
     $details = ArrayObject::ensureArrayObject($payment->getDetails());
     try {
         $request->setModel($details);
         $this->gateway->execute($request);
         $payment->setDetails($details);
         $request->setModel($payment);
     } catch (\Exception $e) {
         $payment->setDetails($details);
         $request->setModel($payment);
         throw $e;
     }
 }
コード例 #3
0
ファイル: CreditHandler.php プロジェクト: csbill/csbill
 /**
  * @param XmlSerializationVisitor $visitor
  * @param Money                   $money
  */
 public function serializeMoneyXml(XmlSerializationVisitor $visitor, Money $money)
 {
     /** @var \DOMElement $node */
     $node = $visitor->getCurrentNode();
     $node->nodeValue = $this->formatter->format($money);
 }
コード例 #4
0
ファイル: MoneyFormatterTest.php プロジェクト: Codixis/CSBill
 /**
  * @param string $locale
  * @param string $pattern
  *
  * @dataProvider patternProvider
  */
 public function testGetPattern($locale, $pattern)
 {
     $formatter = new MoneyFormatter($locale);
     $this->assertContains($pattern, $formatter->getPattern());
 }
コード例 #5
0
ファイル: CurrencyColumn.php プロジェクト: Codixis/CSBill
 /**
  * {@inheritdoc}
  */
 public function getDisplayedValue($value)
 {
     return $this->formatter->format($value);
 }
コード例 #6
0
ファイル: CreditHandler.php プロジェクト: Codixis/CSBill
 /**
  * @param JsonSerializationVisitor $visitor
  * @param Money                    $money
  * @param array                    $type
  * @param Context                  $context
  *
  * @return float
  */
 public function serializeMoney(JsonSerializationVisitor $visitor, Money $money, array $type, Context $context)
 {
     return $this->formatter->toFloat($money);
 }