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
 public function testFromBuy()
 {
     $buy = new Buy();
     $buy->setAmount(new Money(1, CurrencyCode::BTC));
     $buy->setPaymentMethod(new PaymentMethod('PAYMENT_METHOD_ID'));
     $data = $this->mapper->fromBuy($buy);
     $this->assertEquals(['amount' => '1', 'currency' => 'BTC', 'payment_method' => 'PAYMENT_METHOD_ID'], $data);
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 public function testCommitBuy()
 {
     $buy = Buy::reference('ACCOUNT_ID', 'BUY_ID');
     $response = $this->getMock(ResponseInterface::class);
     $this->http->expects($this->once())->method('post')->with('/v2/accounts/ACCOUNT_ID/buys/BUY_ID/commit', ['foo' => 'bar'])->willReturn($response);
     $this->mapper->expects($this->once())->method('toBuy')->with($response, $buy);
     $this->client->commitBuy($buy, ['foo' => 'bar']);
 }