Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
Make sure capture currency does not default to USD (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfosbery authored and tuurbo committed Sep 18, 2019
1 parent fed3af5 commit ac516a7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
24 changes: 20 additions & 4 deletions spec/Tuurbo/Spreedly/TransactionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -133,7 +131,6 @@ public function it_captures_a_specific_authorized_amount($client)
$data = [
'transaction' => [
'amount' => $amount,
'currency_code' => 'USD',
],
];

Expand All @@ -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')
Expand Down
10 changes: 6 additions & 4 deletions src/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ac516a7

Please sign in to comment.