Ejemplo n.º 1
0
 public function testSetTotal()
 {
     $expected = new Money(10, CurrencyCode::USD);
     $buy = new Buy();
     $buy->setTotal($expected);
     $this->assertSame($expected, $buy->getTotal());
 }
Ejemplo n.º 2
0
 /** @return array */
 public function fromBuy(Buy $buy)
 {
     // validate
     if ($buy->getAmount() && $buy->getTotal()) {
         throw new LogicException('The Coinbase API accepts buys with either an amount or a total, but not both');
     }
     // filter
     $data = array_intersect_key($this->extractData($buy), array_flip(['amount', 'total', 'payment_method']));
     // currency
     if (isset($data['amount']['currency'])) {
         $data['currency'] = $data['amount']['currency'];
     } elseif (isset($data['total']['currency'])) {
         $data['currency'] = $data['total']['currency'];
     }
     // amount
     if (isset($data['amount']['amount'])) {
         $data['amount'] = $data['amount']['amount'];
     }
     // total
     if (isset($data['total']['amount'])) {
         $data['total'] = $data['total']['amount'];
     }
     // payment method
     if (isset($data['payment_method']['id'])) {
         $data['payment_method'] = $data['payment_method']['id'];
     }
     return $data;
 }