当前位置: 首页>>代码示例>>PHP>>正文


PHP Money\Money类代码示例

本文整理汇总了PHP中Money\Money的典型用法代码示例。如果您正苦于以下问题:PHP Money类的具体用法?PHP Money怎么用?PHP Money使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Money类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getAmountInBaseUnits

 public function getAmountInBaseUnits(Money $money)
 {
     $iso = $this->iso4217->getByAlpha3($money->getCurrency()->getName());
     $decimals = $iso['exp'];
     $dividend = pow(10, $decimals);
     return $money->getAmount() / $dividend;
 }
开发者ID:jordicasadevall,项目名称:MoneyFormatter,代码行数:7,代码来源:MoneyFormatter.php

示例2: withdraw

 /**
  * Decrease this account current balance
  *
  * @param Money $amount
  * @throws InsufficientFunds
  *     A member cannot withdraw more than it's account current balance
  */
 public function withdraw(Money $amount)
 {
     if ($amount->greaterThan($this->balance)) {
         throw new InsufficientFunds("Cannot withdraw {$amount->getAmount()}");
     }
     $this->balance = $this->balance->subtract($amount);
 }
开发者ID:zoek1,项目名称:php-testing-tools,代码行数:14,代码来源:Account.php

示例3: convert

 /**
  * @param \Money\Money $money
  * @param        $rounding_mode
  * @return \Money\Money
  * @expectedException InvalidArgumentException
  */
 public function convert(Money $money, RoundingMode $rounding_mode = null)
 {
     if (!$money->getCurrency()->equals($this->baseCurrency)) {
         throw new InvalidArgumentException("The Money has the wrong currency");
     }
     $rounding_mode = $rounding_mode ?: RoundingMode::halfUp();
     return new Money((int) round($money->getAmount() * $this->ratio, 0, $rounding_mode->getRoundingMode()), $this->counterCurrency);
 }
开发者ID:srtfisher,项目名称:money,代码行数:14,代码来源:CurrencyPair.php

示例4: convert

 public function convert(Money $money, $target)
 {
     if (!$target instanceof MoneyCurrency) {
         throw new InvalidArgumentException(sprintf('Second argument must be Currency, %s given.', gettype($target)));
     }
     $rate = $this->swap->quote(new CurrencyPair($money->getCurrency(), $target));
     return new Money($money->multiply((double) $rate->getValue())->getAmount(), $target);
 }
开发者ID:umpirsky,项目名称:locurro,代码行数:8,代码来源:Currency.php

示例5: setDiscount

 /**
  * @param Quote|Invoice $object
  * @param Money         $total
  *
  * @return mixed
  */
 private function setDiscount($object, Money $total)
 {
     if (null !== $object->getDiscount()) {
         $discount = $total->multiply($object->getDiscount());
         $total = $total->subtract($discount);
         return $total;
     }
     return $total;
 }
开发者ID:csbill,项目名称:csbill,代码行数:15,代码来源:BillingFormSubscriber.php

示例6: testHydratorHydratesAsExpected

 public function testHydratorHydratesAsExpected()
 {
     $hydrator = new MoneyHydrator();
     $data = ['amount' => 500, 'currency' => 'BRL'];
     $money = new Money(500, new Currency('BRL'));
     $object = $hydrator->hydrate($data, new \stdClass());
     $this->assertEquals($money->getAmount(), $object->getAmount());
     $this->assertEquals($money->getCurrency(), $object->getCurrency());
 }
开发者ID:zfbrasil,项目名称:doctrine-money-module,代码行数:9,代码来源:MoneyHydratorTest.php

示例7: format

 /**
  * {@inheritdoc}
  */
 public function format(Money $money)
 {
     $currencyCode = $money->getCurrency()->getCode();
     if (isset($this->formatters[$currencyCode])) {
         return $this->formatters[$currencyCode]->format($money);
     }
     if (isset($this->formatters['*'])) {
         return $this->formatters['*']->format($money);
     }
     throw new FormatterException('No formatter found for currency ' . $currencyCode);
 }
开发者ID:squigg,项目名称:money,代码行数:14,代码来源:AggregateMoneyFormatter.php

示例8: Rate

 function it_converts_money_using_swap(SwapInterface $swap, Money $money, Money $converted, Currency $from, Currency $to)
 {
     $money->getAmount()->willReturn(100);
     $money->getCurrency()->willReturn($from);
     $money->multiply(120.3971)->willReturn($converted);
     $converted->getAmount()->willReturn(12039);
     $converted->getCurrency()->willReturn($to);
     $from->__toString()->willReturn('EUR');
     $to->__toString()->willReturn('RSD');
     $rate = new Rate(120.3971);
     $swap->quote('EUR/RSD')->shouldBeCalled()->willReturn($rate);
     $this->convert($money, $to)->getAmount()->shouldBe(12039);
 }
开发者ID:umpirsky,项目名称:locurro,代码行数:13,代码来源:CurrencySpec.php

示例9: __construct

 /**
  * @param string $fromMemberId
  * @param string $amount
  * @param string $toMemberId
  * @param string $occurredOn
  */
 public function __construct($fromMemberId, $amount, $toMemberId, $occurredOn)
 {
     $this->occurredOn = DateTime::createFromFormat('Y-m-d H:i:s', $occurredOn);
     $this->fromMemberId = Identifier::fromString($fromMemberId);
     $this->amount = Money::MXN($amount);
     $this->toMemberId = Identifier::fromString($toMemberId);
 }
开发者ID:zoek1,项目名称:php-testing-tools,代码行数:13,代码来源:TransferFundsNotification.php

示例10: JsonSerializer

 /** @test */
 function it_should_serialize_a_domain_event_to_json()
 {
     $serializer = new JsonSerializer();
     $anEvent = new InstantaneousEvent(Identifier::fromString('abc'), Money::MXN(10000), new DateTime('2015-10-24 12:39:51'));
     $json = $serializer->serialize($anEvent);
     $this->assertEquals('{"occurred_on":"2015-10-24 12:39:51","member_id":"abc","amount":10000}', $json, 'JSON format for serialized event is incorrect');
 }
开发者ID:zoek1,项目名称:php-testing-tools,代码行数:8,代码来源:JsonSerializerTest.php

示例11: testOverrideCurrency

 public function testOverrideCurrency()
 {
     \Locale::setDefault("fr_FR");
     $form = $this->factory->create($this->simpleMoneyTypeClass, null, ["currency" => "USD"]);
     $form->submit(array("tbbc_amount" => '1 252,5'));
     $this->assertEquals(Money::USD(125250), $form->getData());
 }
开发者ID:BboyKeen,项目名称:TbbcMoneyBundle,代码行数:7,代码来源:SimpleMoneyTypeTest.php

示例12: __invoke

 /**
  * @return MoneyFieldset
  */
 public function __invoke()
 {
     $moneyFieldset = new MoneyFieldset();
     $moneyFieldset->setHydrator(new MoneyHydrator());
     $moneyFieldset->setObject(Money::BRL(0));
     return $moneyFieldset;
 }
开发者ID:zfbrasil,项目名称:doctrine-money-module,代码行数:10,代码来源:MoneyFieldsetFactory.php

示例13: addEntriesToStatement

 /**
  * @param SimpleXMLElement $statementXml
  * @param Statement $statement
  */
 private function addEntriesToStatement(SimpleXMLElement $statementXml, Statement $statement)
 {
     $index = 0;
     $entriesXml = $statementXml->Ntry;
     foreach ($entriesXml as $entryXml) {
         $amount = Money::stringToUnits((string) $entryXml->Amt);
         $currency = (string) $entryXml->Amt['Ccy'];
         $bookingDate = (string) $entryXml->BookgDt->Dt;
         $valueDate = (string) $entryXml->ValDt->Dt;
         if ((string) $entryXml->CdtDbtInd === 'DBIT') {
             $amount = $amount * -1;
         }
         $entry = new Entry($statement, $index, new Money($amount, new Currency($currency)), new DateTimeImmutable($bookingDate), new DateTimeImmutable($valueDate));
         if (isset($entryXml->RvslInd) && (string) $entryXml->RvslInd === 'true') {
             $entry->setReversalIndicator(true);
         }
         if (isset($entryXml->NtryRef) && (string) $entryXml->NtryRef) {
             $entry->setReference((string) $entryXml->NtryRef);
         }
         if (isset($entryXml->NtryDtls->Btch->PmtInfId) && (string) $entryXml->NtryDtls->Btch->PmtInfId) {
             $entry->setBatchPaymentId((string) $entryXml->NtryDtls->Btch->PmtInfId);
         }
         $this->addTransactionDetailsToEntry($entryXml, $entry);
         $statement->addEntry($entry);
         $index++;
     }
 }
开发者ID:Grummfy,项目名称:camt,代码行数:31,代码来源:Decoder.php

示例14: getPlan

 /**
  * @param PlanDefinition $definition
  * @param Money $amountToPay
  * @param PlanParameters $parameters
  * @return PaymentPlan
  */
 public function getPlan(PlanDefinition $definition, Money $amountToPay, PlanParameters $parameters)
 {
     /** @var array $paymentProportions */
     $paymentProportions = $definition->getAttribute('payments');
     //The values of the payments array is a ratios array
     /** @var Money[] $amounts */
     $amounts = $amountToPay->allocate(array_values($paymentProportions));
     $payments = array_map(function ($rawDate, $amount) {
         //rawDate is either 'immediate' or a 'Y-m-d' string, or invalid.
         if ($rawDate === 'immediate') {
             return PlannedPayment::immediate($amount);
         }
         return PlannedPayment::withDueDate($amount, DueDate::fromString($rawDate));
     }, array_keys($paymentProportions), $amounts);
     return new PaymentPlan($payments, $definition->getAttribute('short_description'), $definition->getAttribute('long_description'));
 }
开发者ID:cambridgeuniversity,项目名称:ice-paymentplan,代码行数:22,代码来源:PercentOnDateCalculator.php

示例15:

 /** @test */
 function it_should_update_the_information_of_a_registered_member()
 {
     $member = $this->members->with(Identifier::fromString('wxyz'));
     $member->transfer(Money::MXN(500), $this->existingMember);
     $this->members->update($this->existingMember);
     $this->assertBalanceAmounts(3500, $this->existingMember, "Current member balance should be 3500");
 }
开发者ID:zoek1,项目名称:php-testing-tools,代码行数:8,代码来源:MembersTest.php


注:本文中的Money\Money类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。