public function testSetTotal() { $expected = new Money(10, CurrencyCode::USD); $sell = new Sell(); $sell->setTotal($expected); $this->assertSame($expected, $sell->getTotal()); }
public function testFromSell() { $sell = new Sell(); $sell->setAmount(new Money(1, CurrencyCode::BTC)); $sell->setPaymentMethod(new PaymentMethod('PAYMENT_METHOD_ID')); $data = $this->mapper->fromSell($sell); $this->assertEquals(['amount' => '1', 'currency' => 'BTC', 'payment_method' => 'PAYMENT_METHOD_ID'], $data); }
/** @return array */ public function fromSell(Sell $sell) { // validate if ($sell->getAmount() && $sell->getTotal()) { throw new LogicException('The Coinbase API accepts sells with either an amount or a total, but not both'); } // filter $data = array_intersect_key($this->extractData($sell), 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; }
public function testCommitSell() { $sell = Sell::reference('ACCOUNT_ID', 'SELL_ID'); $response = $this->getMock(ResponseInterface::class); $this->http->expects($this->once())->method('post')->with('/v2/accounts/ACCOUNT_ID/sells/SELL_ID/commit', ['foo' => 'bar'])->willReturn($response); $this->mapper->expects($this->once())->method('toSell')->with($response, $sell); $this->client->commitSell($sell, ['foo' => 'bar']); }