Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/GlobalGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,9 @@ public function setPassword($value)
{
return $this->setParameter('password', $value);
}

public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\FirstData\Message\GlobalRefundRequest', $parameters);
}
}
34 changes: 34 additions & 0 deletions src/Message/GlobalRefundRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Omnipay\FirstData\Message;

class GlobalRefundRequest extends GlobalAbstractRequest
{
protected $action = self::TRAN_TAGGEDREFUND;

public function getData()
{
$this->setTransactionType($this->action);
$data = $this->getBaseData('DoDirectPayment');

$this->validate('amount', 'transactionReference', 'authorizationCode');

$data['amount'] = $this->getAmount();
$data['currency_code'] = $this->getCurrency();
$data['transaction_tag'] = $this->getTransactionReference();
$data['authorization_num'] = $this->getAuthorizationCode();

$data['client_ip'] = $this->getClientIp();
return $data;
}

public function getAuthorizationCode()
{
return $this->getParameter('authorizationCode');
}

public function setAuthorizationCode($value)
{
return $this->setParameter('authorizationCode', $value);
}
}
7 changes: 6 additions & 1 deletion src/Message/GlobalResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ public function isSuccessful()

public function getTransactionReference()
{
return $this->data['authorization_num'];
return isset($this->data['transaction_tag']) ? $this->data['transaction_tag'] : null;
}

public function getAuthorizationCode()
{
return isset($this->data['authorization_num']) ? $this->data['authorization_num'] : null;
}

public function getMessage()
Expand Down
36 changes: 34 additions & 2 deletions tests/GlobalGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public function setUp()
'currency' => 'USD',
'testMode' => true,
);

$this->refundOptions = array(
'amount' => 13.00,
'transactionReference' => '28513493',
'authorizationCode' => 'ET181147'
);
}

public function testProperties()
Expand All @@ -37,7 +43,8 @@ public function testPurchaseSuccess()

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertEquals('ET181147', $response->getTransactionReference());
$this->assertEquals('28513493', $response->getTransactionReference());
$this->assertEquals('ET181147', $response->getAuthorizationCode());
}

public function testAuthorizeSuccess()
Expand All @@ -48,6 +55,31 @@ public function testAuthorizeSuccess()

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertEquals('ET181147', $response->getTransactionReference());
$this->assertEquals('28513493', $response->getTransactionReference());
$this->assertEquals('ET181147', $response->getAuthorizationCode());
}

public function testRefundSuccess()
{
$this->setMockHttpResponse('RefundSuccess.txt');

$response = $this->gateway->refund($this->refundOptions)->send();

$this->assertTrue($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertEquals('28513493', $response->getTransactionReference());
$this->assertEquals('ET181147', $response->getAuthorizationCode());
}

public function testRefundError()
{
$this->setMockHttpResponse('RefundError.txt');

$response = $this->gateway->refund($this->refundOptions)->send();

$this->assertFalse($response->isSuccessful());
$this->assertFalse($response->isRedirect());
$this->assertEquals('28513493', $response->getTransactionReference());
$this->assertEquals('', $response->getAuthorizationCode());
}
}
9 changes: 7 additions & 2 deletions tests/Message/GlobalPurchaseResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ public function testPurchaseSuccess()
'exact_message' => 'Transaction Normal',
'reference_no' => 'abc123',
'authorization_num' => 'auth1234',
'transaction_tag' => 'tag1234',
'transaction_approved' => 1,
)));

$this->assertTrue($response->isSuccessful());
$this->assertEquals('auth1234', $response->getTransactionReference());
$this->assertEquals('auth1234', $response->getAuthorizationCode());
$this->assertEquals('tag1234', $response->getTransactionReference());
$this->assertSame('Transaction Normal', $response->getMessage());
$this->assertEquals('00', $response->getCode());
}
Expand All @@ -32,11 +34,13 @@ public function testPurchaseError()
'exact_message' => 'Invalid Credit Card Number',
'reference_no' => 'abc123',
'authorization_num' => 'auth1234',
'transaction_tag' => 'tag1234',
'transaction_approved' => 0,
)));

$this->assertFalse($response->isSuccessful());
$this->assertEquals('auth1234', $response->getTransactionReference());
$this->assertEquals('auth1234', $response->getAuthorizationCode());
$this->assertEquals('tag1234', $response->getTransactionReference());
$this->assertSame('Invalid Credit Card Number', $response->getMessage());
$this->assertEquals('22', $response->getCode());
}
Expand All @@ -48,6 +52,7 @@ public function testBankError()
'exact_resp_code' => 00,
'reference_no' => 'abc123',
'authorization_num' => '',
'transaction_tag' => '',
'transaction_approved' => 0,
)));

Expand Down
27 changes: 27 additions & 0 deletions tests/Message/GlobalRefundRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Omnipay\FirstData\Message;

use Omnipay\Tests\TestCase;
use Omnipay\FirstData\Message\GlobalRefundRequest;

class GlobalRefundRequestTest extends TestCase
{
public function testRefundRequest()
{
$request = new GlobalRefundRequest($this->getHttpClient(), $this->getHttpRequest());
$request->initialize(
array(
'amount' => 13.00,
'transactionReference' => '28513493',
'authorizationCode' => 'ET181147'
)
);

$data = $request->getData();
$this->assertEquals('34', $data['transaction_type']);
$this->assertEquals('28513493', $data['transaction_tag']);
$this->assertEquals('ET181147', $data['authorization_num']);
}

}
5 changes: 5 additions & 0 deletions tests/Mock/RefundError.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HTTP/1.1 201 OK
Date: Tue, 11 Feb 2014 02:34:58 GMT
Content-type: text/html; charset=utf-8

account_number=&amount=13.0&amount_requested=&authorization=&authorization_num=&avs=&bank_id=&bank_message=&bank_resp_code=&bank_resp_code_2=&card_cost=&cardholder_name=&cavv=&cavv_algorithm=&cavv_response=&cc_expiry=9999&cc_number=&cc_verification_str1=&cc_verification_str2=&check_number=&check_type=&clerk_id=&client_email=&client_ip=&correlation_id=&credit_card_type=&ctr=&currency_code=USD&current_balance=&customer_id_number=&customer_id_type=&customer_name=&customer_ref=&cvd_presence_ind=0&cvv2=&date_of_birth=&device_id=&ean=&ecommerce_flag=&error_description=&error_number=&exact_message=Invalid+Refund&exact_resp_code=64&fraud_suspected=&gateway_id=AF8163-05&gift_card_amount=&gross_amount_currency_id=&language=&logon_message=&merchant_address=426+Market+St&merchant_city=Chattenooga&merchant_country=United+States&merchant_name=PriceWaiter+DEMO0243&merchant_postal=37402&merchant_province=Tennessee&merchant_url=https%3A%2F%2Fwww.pricewaiter.com%2F&message=&micr=&pan=&partial_redemption=0&password=&payer_id=&previous_balance=&reference_3=&reference_no=order2&registration_date=&registration_no=&release_type=&retrieval_ref_no=&secure_auth_required=&secure_auth_result=&sequence_no=000056&success=&surcharge_amount=&tax1_amount=&tax1_number=&tax2_amount=&tax2_number=&timestamp=&track1=&track2=&transaction_approved=0&transaction_error=1&transaction_tag=28513493&transaction_type=34&transarmor_token=&user_name=&vip=&virtual_card=&xid=&zip_code=
5 changes: 5 additions & 0 deletions tests/Mock/RefundSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HTTP/1.1 201 OK
Date: Tue, 11 Feb 2014 02:34:58 GMT
Content-type: text/html; charset=utf-8

account_number=&amount=13.0&amount_requested=&authorization=&authorization_num=ET181147&avs=&bank_id=&bank_message=Approved&bank_resp_code=100&bank_resp_code_2=&card_cost=&cardholder_name=Example+User&cavv=&cavv_algorithm=&cavv_response=&cc_expiry=0318&cc_number=%23%23%23%23%23%23%23%23%23%23%23%231111&cc_verification_str1=&cc_verification_str2=&check_number=&check_type=&clerk_id=&client_email=&client_ip=&correlation_id=&credit_card_type=Visa&ctr=&currency_code=USD&current_balance=&customer_id_number=&customer_id_type=&customer_name=&customer_ref=&cvd_presence_ind=0&cvv2=&date_of_birth=&device_id=&ean=&ecommerce_flag=&error_description=&error_number=&exact_message=Transaction+Normal&exact_resp_code=00&fraud_suspected=&gateway_id=AF8163-05&gift_card_amount=&gross_amount_currency_id=&language=&logon_message=&merchant_address=426+Market+St&merchant_city=Chattenooga&merchant_country=United+States&merchant_name=PriceWaiter+DEMO0243&merchant_postal=37402&merchant_province=Tennessee&merchant_url=https%3A%2F%2Fwww.pricewaiter.com%2F&message=&micr=&pan=&partial_redemption=0&password=&payer_id=&previous_balance=&reference_3=&reference_no=order2&registration_date=&registration_no=&release_type=&retrieval_ref_no=7775501&secure_auth_required=&secure_auth_result=&sequence_no=000056&success=&surcharge_amount=&tax1_amount=&tax1_number=&tax2_amount=&tax2_number=&timestamp=&track1=&track2=&transaction_approved=1&transaction_error=0&transaction_tag=28513493&transaction_type=34&transarmor_token=&user_name=&vip=&virtual_card=&xid=&zip_code=