示例#1
0
 /**
  * @inheritdoc
  */
 public function getValues()
 {
     $values = ['TYPE' => '00001', 'MONTANT' => $this->amount->getAmount()->unscaledValue(), 'DEVISE' => $this->amount->getCurrency()->getNumericCode(), 'REFERENCE' => $this->reference, 'PORTEUR' => $this->card->getNumber(), 'DATEVAL' => $this->card->getValidity(), 'CVV' => $this->card->getCvv()];
     if ($this->id3d !== null) {
         $values['ID3D'] = $this->id3d;
     }
     return $values;
 }
示例#2
0
 /**
  * @inheritdoc
  */
 public function getValues()
 {
     $values = ['TYPE' => '00051', 'MONTANT' => $this->amount->getAmount()->unscaledValue(), 'DEVISE' => $this->amount->getCurrency()->getNumericCode(), 'REFERENCE' => $this->paymentReference, 'REFABONNE' => $this->subscriberReference, 'PORTEUR' => $this->token, 'DATEVAL' => $this->validity];
     if ($this->cvv !== null) {
         $values['CVV'] = $this->cvv;
     }
     return $values;
 }
示例#3
0
 /**
  * @param Money    $money
  * @param Currency $currency
  *
  * @return Money
  *
  * @throws CurrencyConversionException If the exchange rate is not available.
  * @throws RoundingNecessaryException  If rounding was necessary but this converter uses RoundingMode::UNNECESSARY.
  */
 public function convert(Money $money, Currency $currency)
 {
     if ($money->getCurrency()->is($currency)) {
         $exchangeRate = 1;
     } else {
         $exchangeRate = $this->exchangeRateProvider->getExchangeRate($money->getCurrency()->getCode(), $currency->getCode());
     }
     return $money->convertedTo($currency, $exchangeRate, $this->context);
 }
示例#4
0
文件: Money.php 项目: brick/money
 /**
  * Returns the maximum of the given monies.
  *
  * If several monies are equal to the maximum value, the first one is returned.
  *
  * @param Money    $money  The first money.
  * @param Money ...$monies The subsequent monies.
  *
  * @return Money
  *
  * @throws CurrencyMismatchException If all the monies are not in the same currency.
  */
 public static function max(Money $money, Money ...$monies)
 {
     $max = $money;
     foreach ($monies as $money) {
         if ($money->isGreaterThan($max)) {
             $max = $money;
         }
     }
     return $max;
 }
示例#5
0
 /**
  * Returns an array of POST parameters to use to redirect the customer to the 3D Secure authentication page.
  *
  * These parameters can be used to build a web form to post in the user's browser.
  *
  * @param Card  $card       The payment card.
  * @param Money $amount     The amount of the transaction.
  * @param string $sessionId A unique session ID of up to 250 chars.
  *                          This session ID will be returned in the callback,
  *                          and used to identify this 3D Secure authentication.
  *
  * @return array
  */
 public function getPostParameters(Card $card, Money $amount, $sessionId)
 {
     $parameters = ['Amount' => $amount->getAmount()->unscaledValue(), 'Currency' => $amount->getCurrency()->getNumericCode(), 'CCNumber' => $card->getNumber(), 'CCExpDate' => $card->getValidity(), 'CVVCode' => $card->getCvv(), 'IdMerchant' => $this->paybox->getIdentifier(), 'IdSession' => $sessionId];
     if ($this->callbackUrl !== null) {
         $parameters['URLHttpDirect'] = $this->callbackUrl;
     }
     if ($this->returnUrl !== null) {
         $parameters['URLRetour'] = $this->returnUrl;
     }
     return $parameters;
 }
示例#6
0
 /**
  * Compares the given monies.
  *
  * The amount is not rounded before comparison, so the results are more relevant than when using
  * `convert($a, $b->getCurrency())->compareTo($b)`.
  *
  * Note that the comparison is performed by converting A into B's currency.
  * This order is important if the exchange rate provider uses different exchange rates
  * when converting back and forth two currencies.
  *
  * @param Money $a
  * @param Money $b
  *
  * @return int -1, 0 or 1.
  *
  * @throws CurrencyConversionException If the exchange rate is not available.
  */
 public function compare(Money $a, Money $b)
 {
     $aCurrencyCode = $a->getCurrency()->getCode();
     $bCurrencyCode = $b->getCurrency()->getCode();
     if ($aCurrencyCode === $bCurrencyCode) {
         return $a->compareTo($b);
     }
     $aAmount = $a->getAmount();
     $bAmount = $b->getAmount();
     $exchangeRate = $this->exchangeRateProvider->getExchangeRate($aCurrencyCode, $bCurrencyCode);
     $aAmount = $aAmount->toBigRational()->multipliedBy($exchangeRate);
     return $aAmount->compareTo($bAmount);
 }
示例#7
0
文件: MoneyBag.php 项目: brick/money
 /**
  * Returns the total of the monies contained in this bag, in the given currency.
  *
  * @param Currency          $currency  The currency to get the total in.
  * @param CurrencyConverter $converter The currency converter to use.
  *
  * @return Money The total in the given currency.
  */
 public function getTotal(Currency $currency, CurrencyConverter $converter)
 {
     $total = Money::zero($currency);
     $context = new ExactContext();
     foreach ($this->monies as $money) {
         $money = $converter->convert($money, $currency);
         $total = $total->plus($money, $context);
     }
     return $total;
 }
示例#8
0
 /**
  * @dataProvider providerConvert
  *
  * @param string $money          The string representation of the base money.
  * @param string $currency       The currency code to convert to.
  * @param int    $roundingMode   The rounding mode to use.
  * @param string $expectedResult The expected money's string representation, or an exception class name.
  */
 public function testConvert($money, $currency, $roundingMode, $expectedResult)
 {
     $money = Money::parse($money);
     $currency = Currency::of($currency);
     $currencyConverter = $this->createCurrencyConverter($roundingMode);
     if ($this->isExceptionClass($expectedResult)) {
         $this->setExpectedException($expectedResult);
     }
     $actualResult = $currencyConverter->convert($money, $currency);
     if (!$this->isExceptionClass($expectedResult)) {
         $this->assertMoneyIs($expectedResult, $actualResult);
     }
 }
示例#9
0
 /**
  * @depends testNewMoneyBagIsEmpty
  *
  * @param MoneyBag $moneyBag
  *
  * @return MoneyBag
  */
 public function testAddSubtractMoney(MoneyBag $moneyBag)
 {
     $moneyBag->add(Money::of('123', 'EUR'));
     $this->assertMoneyBagContains(['EUR 123.00'], $moneyBag);
     $moneyBag->add(Money::of('234.99', 'EUR'));
     $this->assertMoneyBagContains(['EUR 357.99'], $moneyBag);
     $moneyBag->add(Money::of(3, 'JPY'));
     $this->assertMoneyBagContains(['EUR 357.99', 'JPY 3'], $moneyBag);
     $moneyBag->add(Money::parse('JPY 1.1234'));
     $this->assertMoneyBagContains(['EUR 357.99', 'JPY 4.1234'], $moneyBag);
     $moneyBag->subtract(Money::parse('EUR 3.589950'));
     $this->assertMoneyBagContains(['EUR 354.400050', 'JPY 4.1234'], $moneyBag);
     return $moneyBag;
 }
示例#10
0
 /**
  * @param array    $expectedMonies
  * @param MoneyBag $moneyBag
  */
 protected final function assertMoneyBagContains(array $expectedMonies, $moneyBag)
 {
     $this->assertInstanceOf(MoneyBag::class, $moneyBag);
     // Test get() on each currency
     foreach ($expectedMonies as $money) {
         $money = Money::parse($money);
         $this->assertMoneyIs($money, $moneyBag->get($money->getCurrency()));
     }
     $actualMonies = $moneyBag->getMonies();
     foreach ($actualMonies as &$money) {
         $money = (string) $money;
     }
     sort($expectedMonies);
     sort($actualMonies);
     // Test getMonies()
     $this->assertSame($expectedMonies, $actualMonies);
 }
示例#11
0
 /**
  * @inheritdoc
  */
 public function getValues()
 {
     return ['TYPE' => '00002', 'MONTANT' => $this->amount->getAmount()->unscaledValue(), 'DEVISE' => $this->amount->getCurrency()->getNumericCode(), 'NUMAPPEL' => $this->numappel, 'NUMTRANS' => $this->numtrans, 'REFERENCE' => $this->reference];
 }
示例#12
0
 /**
  * @dataProvider providerMax
  *
  * @param array $monies       The monies to compare.
  * @param string $expectedMin The expected maximum money, or an exception class.
  */
 public function testMax(array $monies, $expectedMin)
 {
     $comparator = new MoneyComparator($this->getExchangeRateProvider());
     foreach ($monies as &$money) {
         $money = Money::parse($money);
     }
     if ($this->isExceptionClass($expectedMin)) {
         $this->setExpectedException($expectedMin);
     }
     $actualMin = $comparator->max(...$monies);
     if (!$this->isExceptionClass($expectedMin)) {
         $this->assertMoneyIs($expectedMin, $actualMin);
     }
 }
示例#13
0
文件: MoneyTest.php 项目: brick/money
 /**
  * @expectedException \Brick\Money\Exception\CurrencyMismatchException
  */
 public function testTotalOfDifferentCurrenciesThrowsException()
 {
     Money::total(Money::parse('EUR 1.00'), Money::parse('USD 1.00'));
 }
示例#14
0
 /**
  * PayboxSystemRequest constructor.
  *
  * @param Money  $amount
  * @param string $reference
  * @param string $email
  */
 public function __construct(Money $amount, $reference, $email)
 {
     $this->values = ['PBX_TOTAL' => $amount->getAmount()->unscaledValue(), 'PBX_DEVISE' => $amount->getCurrency()->getNumericCode(), 'PBX_CMD' => $reference, 'PBX_PORTEUR' => $email, 'PBX_RETOUR' => 'M:M;R:R;T:T;A:A;B:B;C:C;D:D;E:E;F:F;G:G;H:H;I:I;J:J;N:N;O:O;P:P;Q:Q;S:S;U:U;W:W;Y:Y;K:K', 'PBX_HASH' => 'SHA512', 'PBX_TIME' => gmdate('c')];
 }
示例#15
0
 /**
  * @inheritdoc
  */
 public function getValues()
 {
     return ['TYPE' => '00055', 'REFABONNE' => $this->subscriberReference, 'REFERENCE' => $this->paymentReference, 'MONTANT' => $this->amount->getAmount()->unscaledValue(), 'DEVISE' => $this->amount->getCurrency()->getNumericCode(), 'NUMAPPEL' => $this->numappel, 'NUMTRANS' => $this->numtrans, 'PORTEUR' => $this->token, 'DATEVAL' => $this->validity];
 }
 /**
  * @inheritdoc
  */
 public function getValues()
 {
     return ['TYPE' => '00061', 'MONTANT' => $this->amount->getAmount()->unscaledValue(), 'DEVISE' => $this->amount->getCurrency()->getNumericCode(), 'REFERENCE' => $this->reference, 'REFABONNE' => $this->refabonne, 'PORTEUR' => $this->token, 'DATEVAL' => $this->validity];
 }
 /**
  * @inheritdoc
  */
 public function getValues()
 {
     return ['TYPE' => '00011', 'MONTANT' => $this->amount->getAmount()->unscaledValue(), 'DEVISE' => $this->amount->getCurrency()->getNumericCode(), 'REFERENCE' => $this->reference];
 }
 /**
  * @inheritdoc
  */
 public function getValues()
 {
     return ['TYPE' => '00012', 'MONTANT' => $this->amount->getAmount()->unscaledValue(), 'DEVISE' => $this->amount->getCurrency()->getNumericCode(), 'REFERENCE' => $this->reference, 'PORTEUR' => $this->card->getNumber(), 'DATEVAL' => $this->card->getValidity(), 'CVV' => $this->card->getCvv()];
 }
示例#19
0
 public function testInquire()
 {
     $card = new Card('1111222233334444', '1216', '123');
     $amount = Money::of(10, 'EUR');
     $reference = __FUNCTION__ . '-' . time();
     $paybox = $this->getTestPayboxDirectInstance();
     $request = new AuthorizeAndCapture($card, $amount, $reference);
     $captureResponse = $paybox->execute($request);
     $this->assertResponseStatus($captureResponse, PayboxDirectResponse::SUCCESS);
     $request = new Inquire($captureResponse->getNumtrans());
     $response = $paybox->execute($request);
     $this->assertResponseStatus($response, PayboxDirectResponse::SUCCESS);
     $this->assertSame($captureResponse->getNumappel(), $response->getNumappel());
     $this->assertSame($captureResponse->getNumtrans(), $response->getNumtrans());
     $this->assertSame(utf8_decode('Capturé'), $response->getStatus());
 }