-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from nuryagdym/unit-tests-for-garantipos
fix issue #50 Garanti POS undefined index on fail response
- Loading branch information
Showing
2 changed files
with
173 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
use Mews\Pos\Gateways\AbstractGateway; | ||
use Mews\Pos\Gateways\GarantiPos; | ||
use PHPUnit\Framework\TestCase; | ||
use ReflectionClass; | ||
use ReflectionMethod; | ||
use Symfony\Component\Serializer\Encoder\XmlEncoder; | ||
|
||
class GarantiPosTest extends TestCase | ||
|
@@ -319,6 +321,109 @@ public function testCreateRefundXML() | |
//$this->assertEquals([], $actualData['Transaction']); | ||
} | ||
|
||
/** | ||
* @uses \Mews\Pos\Gateways\GarantiPos::map3DPayResponseData() | ||
* | ||
* @return void | ||
*/ | ||
public function testMap3DPayResponseDataSuccess() | ||
{ | ||
$gatewayResponse = [ | ||
"xid" => "bVi+A/h6SjXabcde=", | ||
"mdstatus" => "1", | ||
"mderrormessage" => "TROY Gateway Result: [Code: '000', Message: 'Success', Description: 'Successful']", | ||
"txnstatus" => "", | ||
"eci" => "", | ||
"cavv" => "ABIBBDYABBBBBAAABAAAAAAAAAAA=", | ||
"paressyntaxok" => "", | ||
"paresverified" => "", | ||
"version" => "", | ||
"ireqcode" => "", | ||
"ireqdetail" => "", | ||
"vendorcode" => "", | ||
"cavvalgorithm" => "", | ||
"md" => "longstring", | ||
"terminalid" => "10012345", | ||
"oid" => "1221513409", | ||
"authcode" => "", | ||
"response" => "", | ||
"errmsg" => "", | ||
"hostmsg" => "", | ||
"procreturncode" => "", | ||
"transid" => "1001513409", | ||
"hostrefnum" => "", | ||
"rnd" => "vNOc4abcde2aCL/HBzs", | ||
"hash" => "1I9zDunx0hashTRI816trOG0Ao0=", | ||
"hashparams" => "clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:", | ||
"hashparamsval" => "longstring", | ||
"clientid" => "10012345", | ||
"MaskedPan" => "454311***7965", | ||
"customeripaddress" => "134.170.165.149", | ||
"orderid" => "1221513409", | ||
"txntype" => "sales", | ||
"terminalprovuserid" => "PROVAUT", | ||
"secure3dhash" => "BE3C507794AhashE021E8EA239415D774EEF2", | ||
"mode" => "PROD", | ||
"txncurrencycode" => "949", | ||
"customeremailaddress" => "[email protected]", | ||
"terminaluserid" => "PROVAUT", | ||
"terminalmerchantid" => "1234567", | ||
"secure3dsecuritylevel" => "3D", | ||
"user_id" => "1", | ||
"errorurl" => "https://example.com/odeme_basarisiz", | ||
"apiversion" => "v0.01", | ||
"txnamount" => "100", | ||
"txninstallmentcount" => "", | ||
"successurl" => "https://example.com/odeme_basarili", | ||
]; | ||
$expected = '{"id":"","order_id":"1221513409","trans_id":"1001513409","auth_code":"","host_ref_num":"","response":"Approved","transaction_type":null,"transaction":null,"transaction_security":"Full 3D Secure","proc_return_code":"","code":"","md_status":"1","status":"approved","status_detail":null,"hash":"BE3C507794AhashE021E8EA239415D774EEF2","rand":"vNOc4abcde2aCL\/HBzs","hash_params":"clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:","hash_params_val":"longstring","masked_number":"454311***7965","amount":"100","currency":"949","tx_status":"","eci":"","cavv":"ABIBBDYABBBBBAAABAAAAAAAAAAA=","xid":"bVi+A\/h6SjXabcde=","error_code":null,"error_message":"","md_error_message":"TROY Gateway Result: [Code: \'000\', Message: \'Success\', Description: \'Successful\']","campaign_url":null,"email":"[email protected]","extra":null,"all":{"xid":"bVi+A\/h6SjXabcde=","mdstatus":"1","mderrormessage":"TROY Gateway Result: [Code: \'000\', Message: \'Success\', Description: \'Successful\']","txnstatus":"","eci":"","cavv":"ABIBBDYABBBBBAAABAAAAAAAAAAA=","paressyntaxok":"","paresverified":"","version":"","ireqcode":"","ireqdetail":"","vendorcode":"","cavvalgorithm":"","md":"longstring","terminalid":"10012345","oid":"1221513409","authcode":"","response":"","errmsg":"","hostmsg":"","procreturncode":"","transid":"1001513409","hostrefnum":"","rnd":"vNOc4abcde2aCL\/HBzs","hash":"1I9zDunx0hashTRI816trOG0Ao0=","hashparams":"clientid:oid:authcode:procreturncode:response:mdstatus:cavv:eci:md:rnd:","hashparamsval":"longstring","clientid":"10012345","MaskedPan":"454311***7965","customeripaddress":"134.170.165.149","orderid":"1221513409","txntype":"sales","terminalprovuserid":"PROVAUT","secure3dhash":"BE3C507794AhashE021E8EA239415D774EEF2","mode":"PROD","txncurrencycode":"949","customeremailaddress":"[email protected]","terminaluserid":"PROVAUT","terminalmerchantid":"1234567","secure3dsecuritylevel":"3D","user_id":"1","errorurl":"https:\/\/example.com\/odeme_basarisiz","apiversion":"v0.01","txnamount":"100","txninstallmentcount":"","successurl":"https:\/\/example.com\/odeme_basarili"}}'; | ||
$method = $this->getMethod('map3DPayResponseData'); | ||
$result1 = $method->invoke($this->pos, $gatewayResponse); | ||
|
||
$this->assertIsObject($result1); | ||
$this->assertSame($expected, json_encode($result1)); | ||
} | ||
|
||
/** | ||
* @uses \Mews\Pos\Gateways\GarantiPos::map3DPayResponseData() | ||
* | ||
* @return void | ||
*/ | ||
public function testMap3DPayResponseDataFail() | ||
{ | ||
$failResponse = [ | ||
"mdstatus" => "0", | ||
"mderrormessage" => "User Gave Up", | ||
"errmsg" => "User Gave Up", | ||
"clientid" => "10012345", | ||
"oid" => "1221166825", | ||
"response" => "Error", | ||
"procreturncode" => "99", | ||
"customeripaddress" => "111.222.333.444", | ||
"orderid" => "1221166825", | ||
"txntype" => "sales", | ||
"terminalprovuserid" => "PROVAUT", | ||
"secure3dhash" => "hashhash", | ||
"mode" => "PROD", | ||
"terminalid" => "10012345", | ||
"txncurrencycode" => "949", | ||
"customeremailaddress" => "[email protected]", | ||
"terminaluserid" => "PROVAUT", | ||
"terminalmerchantid" => "5220607", | ||
"secure3dsecuritylevel" => "3D", | ||
"user_id" => "1", | ||
"errorurl" => "https://example.com/odeme_basarisiz", | ||
"apiversion" => "v0.01", | ||
"txnamount" => "9000", | ||
"txninstallmentcount" => "", | ||
"successurl" => "https://example.com/odeme_basarili", | ||
]; | ||
$expected = '{"id":null,"order_id":"1221166825","trans_id":null,"auth_code":null,"host_ref_num":null,"response":"Declined","transaction_type":null,"transaction":null,"transaction_security":"MPI fallback","proc_return_code":"99","code":"99","md_status":"0","status":"declined","status_detail":"99","hash":"hashhash","rand":null,"hash_params":null,"hash_params_val":null,"masked_number":null,"amount":"9000","currency":"949","tx_status":null,"eci":null,"cavv":null,"xid":null,"error_code":"99","error_message":"User Gave Up","md_error_message":"User Gave Up","campaign_url":null,"email":"[email protected]","extra":null,"all":{"mdstatus":"0","mderrormessage":"User Gave Up","errmsg":"User Gave Up","clientid":"10012345","oid":"1221166825","response":"Error","procreturncode":"99","customeripaddress":"111.222.333.444","orderid":"1221166825","txntype":"sales","terminalprovuserid":"PROVAUT","secure3dhash":"hashhash","mode":"PROD","terminalid":"10012345","txncurrencycode":"949","customeremailaddress":"[email protected]","terminaluserid":"PROVAUT","terminalmerchantid":"5220607","secure3dsecuritylevel":"3D","user_id":"1","errorurl":"https:\/\/example.com\/odeme_basarisiz","apiversion":"v0.01","txnamount":"9000","txninstallmentcount":"","successurl":"https:\/\/example.com\/odeme_basarili"}}'; | ||
$method = $this->getMethod('map3DPayResponseData'); | ||
$result1 = $method->invoke($this->pos, $failResponse); | ||
$this->assertSame($expected, json_encode($result1)); | ||
} | ||
|
||
/** | ||
* @param $order | ||
* @param CreditCardGarantiPos $card | ||
|
@@ -597,4 +702,13 @@ private function getSampleRefundXMLData($order, $account) | |
], | ||
]; | ||
} | ||
|
||
private static function getMethod(string $name): ReflectionMethod | ||
{ | ||
$class = new ReflectionClass(GarantiPos::class); | ||
$method = $class->getMethod($name); | ||
$method->setAccessible(true); | ||
|
||
return $method; | ||
} | ||
} |