/** * @param string $currency * @return Currency */ public function currency($currency = null) { if ($currency !== null) { $this->currency = Currency::fromString($currency); } return $this->currency; }
/** * @param array $transaction * @return Transaction */ public static function fromArray(array $transaction) { Guard::keyExists($transaction, 'payment_method'); $paymentMethod = PaymentMethod::fromString($transaction['payment_method']); return new static($paymentMethod, PaymentMethodDetails\PaymentMethodDetailsFactory::createFromArray($paymentMethod, array_key_exists('payment_method_details', $transaction) ? $transaction['payment_method_details'] : []), array_key_exists('id', $transaction) ? Uuid::fromString($transaction['id']) : null, array_key_exists('created', $transaction) ? new Carbon($transaction['created']) : null, array_key_exists('modified', $transaction) ? new Carbon($transaction['modified']) : null, array_key_exists('completed', $transaction) ? new Carbon($transaction['completed']) : null, array_key_exists('status', $transaction) ? TransactionStatus::fromString($transaction['status']) : null, array_key_exists('reason', $transaction) ? Reason::fromString($transaction['reason']) : null, array_key_exists('currency', $transaction) ? Currency::fromString($transaction['currency']) : null, array_key_exists('amount', $transaction) ? TransactionAmount::fromInteger($transaction['amount']) : null, array_key_exists('expiration_period', $transaction) ? new \DateInterval($transaction['expiration_period']) : null, array_key_exists('description', $transaction) ? TransactionDescription::fromString($transaction['description']) : null, array_key_exists('balance', $transaction) ? Balance::fromString($transaction['balance']) : null, array_key_exists('payment_url', $transaction) ? Url::fromString($transaction['payment_url']) : null); }
/** * @param array $order * @return Order */ public static function fromArray(array $order) { Guard::keyExists($order, 'transactions'); Guard::keyExists($order, 'amount'); Guard::keyExists($order, 'currency'); return new static(Transactions::fromArray($order['transactions']), Amount::fromInteger($order['amount']), Currency::fromString($order['currency']), array_key_exists('description', $order) ? Description::fromString($order['description']) : null, array_key_exists('merchant_order_id', $order) ? MerchantOrderId::fromString($order['merchant_order_id']) : null, array_key_exists('return_url', $order) ? Url::fromString($order['return_url']) : null, array_key_exists('expiration_period', $order) ? new \DateInterval($order['expiration_period']) : null, array_key_exists('id', $order) ? Uuid::fromString($order['id']) : null, array_key_exists('project_id', $order) ? Uuid::fromString($order['project_id']) : null, array_key_exists('created', $order) ? new Carbon($order['created']) : null, array_key_exists('modified', $order) ? new Carbon($order['modified']) : null, array_key_exists('completed', $order) ? new Carbon($order['completed']) : null, array_key_exists('status', $order) ? Status::fromString($order['status']) : null); }
/** * @test */ public function itShouldGuardAgainstInvalidCurrency() { $this->setExpectedException('Assert\\InvalidArgumentException'); Currency::fromString('USD'); }