diff --git a/spec/Tuurbo/Spreedly/TransactionSpec.php b/spec/Tuurbo/Spreedly/TransactionSpec.php index a8e95a5..2f2769f 100644 --- a/spec/Tuurbo/Spreedly/TransactionSpec.php +++ b/spec/Tuurbo/Spreedly/TransactionSpec.php @@ -114,9 +114,7 @@ public function it_credits_a_purchase_with_no_amount_specified_and_with_extra_da public function it_captures_an_authorized_amount($client) { $data = [ - 'transaction' => [ - 'currency_code' => 'USD', - ], + 'transaction' => [], ]; $client->post('v1/transactions/'.self::TRANSACTION_TOKEN.'/capture.json', $data) @@ -133,7 +131,6 @@ public function it_captures_a_specific_authorized_amount($client) $data = [ 'transaction' => [ 'amount' => $amount, - 'currency_code' => 'USD', ], ]; @@ -144,6 +141,25 @@ public function it_captures_a_specific_authorized_amount($client) $this->capture($amount)->shouldReturnAnInstanceOf('Tuurbo\Spreedly\Client'); } + public function it_captures_a_specific_authorized_amount_and_currency($client) + { + $amount = 9.99; + $currencyCode = 'USD'; + + $data = [ + 'transaction' => [ + 'amount' => $amount, + 'currency_code' => $currencyCode, + ], + ]; + + $client->post('v1/transactions/'.self::TRANSACTION_TOKEN.'/capture.json', $data) + ->shouldBeCalled() + ->willReturn($client); + + $this->capture($amount, $currencyCode)->shouldReturnAnInstanceOf('Tuurbo\Spreedly\Client'); + } + public function it_completes_a_3ds2_transaction($client) { $client->post('v1/transactions/'.self::TRANSACTION_TOKEN.'/complete.json') diff --git a/src/Transaction.php b/src/Transaction.php index 4e00363..3f34e3e 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -151,14 +151,16 @@ public function transcript() * * @return \Tuurbo\Spreedly\Client */ - public function capture($amount = null, $currency = 'USD', array $data = []) + public function capture($amount = null, $currency = null, array $data = []) { $params = [ - 'transaction' => [ - 'currency_code' => $currency, - ], + 'transaction' => [], ]; + if ($currency !== null) { + $params['transaction']['currency_code'] = $currency; + } + if ($amount > 0) { $params['transaction']['amount'] = $amount; }