本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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());
}
示例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);
}
示例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);
}
示例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);
}
示例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');
}
示例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());
}
示例12: __invoke
/**
* @return MoneyFieldset
*/
public function __invoke()
{
$moneyFieldset = new MoneyFieldset();
$moneyFieldset->setHydrator(new MoneyHydrator());
$moneyFieldset->setObject(Money::BRL(0));
return $moneyFieldset;
}
示例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++;
}
}
示例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'));
}
示例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");
}