Add remaining project files (exclude ignored folders)
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans;
|
||||
|
||||
class MT_Tests
|
||||
{
|
||||
public static $stubHttp = false;
|
||||
public static $stubHttpResponse;
|
||||
public static $stubHttpStatus;
|
||||
public static $lastHttpRequest;
|
||||
|
||||
public static function reset()
|
||||
{
|
||||
MT_Tests::$stubHttp = false;
|
||||
MT_Tests::$stubHttpResponse = null;
|
||||
MT_Tests::$lastHttpRequest = null;
|
||||
}
|
||||
|
||||
public static function lastReqOptions()
|
||||
{
|
||||
$consts = array(
|
||||
CURLOPT_URL => "URL",
|
||||
CURLOPT_HTTPHEADER => "HTTPHEADER",
|
||||
CURLOPT_RETURNTRANSFER => "RETURNTRANSFER",
|
||||
CURLOPT_CAINFO => "CAINFO",
|
||||
CURLOPT_POST => "POST",
|
||||
CURLOPT_POSTFIELDS => "POSTFIELDS",
|
||||
CURLOPT_PROXY => "PROXY"
|
||||
);
|
||||
|
||||
$options = array();
|
||||
foreach (MT_Tests::$lastHttpRequest["curl"] as $intValue => $value) {
|
||||
$key = $consts[$intValue] ? $consts[$intValue] : $intValue;
|
||||
$options[$key] = $value;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans;
|
||||
|
||||
class MidtransApiRequestorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testConfigOptionsOverrideCurlOptions()
|
||||
{
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{ "status_code": "200" }';
|
||||
|
||||
Config::$curlOptions = array(
|
||||
CURLOPT_HTTPHEADER => array( "User-Agent: testing lib" ),
|
||||
CURLOPT_PROXY => "http://proxy.com"
|
||||
);
|
||||
|
||||
$resp = ApiRequestor::post("http://proxy.com", "dummy", "");
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertTrue(in_array("User-Agent: testing lib", $fields["HTTPHEADER"]));
|
||||
$this->assertTrue(in_array('Content-Type: application/json', $fields["HTTPHEADER"]));
|
||||
|
||||
$this->assertEquals("http://proxy.com", $fields["PROXY"]);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
MT_Tests::reset();
|
||||
Config::$curlOptions = array();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans;
|
||||
|
||||
class MidtransConfigTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testReturnBaseUrl()
|
||||
{
|
||||
Config::$isProduction = false;
|
||||
$this->assertEquals(
|
||||
Config::getBaseUrl(),
|
||||
Config::SANDBOX_BASE_URL
|
||||
);
|
||||
|
||||
Config::$isProduction = true;
|
||||
$this->assertEquals(Config::PRODUCTION_BASE_URL, Config::getBaseUrl());
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
Config::$isProduction = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans;
|
||||
|
||||
class MidtransCoreApiTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testCharge()
|
||||
{
|
||||
Config::$appendNotifUrl = "https://example.com";
|
||||
Config::$overrideNotifUrl = "https://example.com";
|
||||
Config::$paymentIdempotencyKey = "123456";
|
||||
Config::$serverKey = "dummy";
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code": 200,
|
||||
"redirect_url": "http://host.com/pay"
|
||||
}';
|
||||
|
||||
$params = array(
|
||||
'transaction_details' => array(
|
||||
'order_id' => "Order-111",
|
||||
'gross_amount' => 10000,
|
||||
)
|
||||
);
|
||||
|
||||
$charge = CoreApi::charge($params);
|
||||
|
||||
$this->assertEquals($charge->status_code, "200");
|
||||
|
||||
$this->assertEquals(
|
||||
MT_Tests::$lastHttpRequest["url"],
|
||||
"https://api.sandbox.midtrans.com/v2/charge"
|
||||
);
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertEquals($fields["POST"], 1);
|
||||
$this->assertEquals(
|
||||
$fields["POSTFIELDS"],
|
||||
'{"payment_type":"credit_card","transaction_details":{"order_id":"Order-111","gross_amount":10000}}'
|
||||
);
|
||||
$this->assertTrue(in_array('X-Append-Notification: https://example.com', $fields["HTTPHEADER"]));
|
||||
$this->assertTrue(in_array('X-Override-Notification: https://example.com', $fields["HTTPHEADER"]));
|
||||
$this->assertTrue(in_array('Idempotency-Key: 123456', $fields["HTTPHEADER"]));
|
||||
}
|
||||
|
||||
public function testRealConnectWithInvalidKey()
|
||||
{
|
||||
Config::$serverKey = 'invalid-server-key';
|
||||
$params = array(
|
||||
'transaction_details' => array(
|
||||
'order_id' => rand(),
|
||||
'gross_amount' => 10000,
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
$paymentUrl = CoreApi::charge($params);
|
||||
} catch (\Exception $error) {
|
||||
$this->assertContains("Midtrans API is returning API error. HTTP status code: 401", $error->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testCapture()
|
||||
{
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code": "200",
|
||||
"status_message": "Success, Credit Card capture transaction is successful",
|
||||
"transaction_id": "1ac1a089d-a587-40f1-a936-a7770667d6dd",
|
||||
"order_id": "A27550",
|
||||
"payment_type": "credit_card",
|
||||
"transaction_time": "2014-08-25 10:20:54",
|
||||
"transaction_status": "capture",
|
||||
"fraud_status": "accept",
|
||||
"masked_card": "481111-1114",
|
||||
"bank": "bni",
|
||||
"approval_code": "1408937217061",
|
||||
"gross_amount": "55000.00"
|
||||
}';
|
||||
|
||||
$capture = CoreApi::capture("A27550");
|
||||
|
||||
$this->assertEquals($capture->status_code, "200");
|
||||
|
||||
$this->assertEquals("https://api.sandbox.midtrans.com/v2/capture", MT_Tests::$lastHttpRequest["url"]);
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertEquals(1, $fields["POST"]);
|
||||
$this->assertEquals('{"transaction_id":"A27550"}', $fields["POSTFIELDS"]);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
MT_Tests::reset();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans;
|
||||
|
||||
require_once dirname(__FILE__) . '/../Midtrans.php';
|
||||
|
||||
define(
|
||||
'TEST_CAPTURE_JSON', '{
|
||||
"status_code" : "200",
|
||||
"status_message" : "Midtrans payment notification",
|
||||
"transaction_id" : "826acc53-14e0-4ae7-95e2-845bf0311579",
|
||||
"order_id" : "2014040745",
|
||||
"payment_type" : "credit_card",
|
||||
"transaction_time" : "2014-04-07 16:22:36",
|
||||
"transaction_status" : "capture",
|
||||
"fraud_status" : "accept",
|
||||
"masked_card" : "411111-1111",
|
||||
"gross_amount" : "2700"
|
||||
}'
|
||||
);
|
||||
|
||||
class MidtransNotificationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testCanWorkWithJSON()
|
||||
{
|
||||
$tmpfname = tempnam(sys_get_temp_dir(), "midtrans_test");
|
||||
file_put_contents($tmpfname, TEST_CAPTURE_JSON);
|
||||
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = TEST_CAPTURE_JSON;
|
||||
|
||||
Config::$serverKey = 'dummy';
|
||||
$notif = new Notification($tmpfname);
|
||||
|
||||
$this->assertEquals("capture", $notif->transaction_status);
|
||||
$this->assertEquals("credit_card", $notif->payment_type);
|
||||
$this->assertEquals("2014040745", $notif->order_id);
|
||||
$this->assertEquals("2700", $notif->gross_amount);
|
||||
|
||||
unlink($tmpfname);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
MT_Tests::reset();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Midtrans;
|
||||
|
||||
use Midtrans\utility\MtChargeFixture;
|
||||
|
||||
class MidtransSanitizerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testSanitizeWithoutOptionalRequest()
|
||||
{
|
||||
$params = MtChargeFixture::build('vtweb');
|
||||
unset($params['customer_details']);
|
||||
|
||||
Sanitizer::jsonRequest($params);
|
||||
$this->assertEquals(false, isset($params['customer_details']));
|
||||
}
|
||||
|
||||
public function testSanitizeWithoutOptionalCustDetails()
|
||||
{
|
||||
$params = MtChargeFixture::build('vtweb');
|
||||
unset($params['customer_details']['first_name']);
|
||||
unset($params['customer_details']['last_name']);
|
||||
unset($params['customer_details']['email']);
|
||||
unset($params['customer_details']['billing_address']);
|
||||
unset($params['customer_details']['shipping_address']);
|
||||
|
||||
Sanitizer::jsonRequest($params);
|
||||
|
||||
$this->assertEquals(false, isset($params['customer_details']['first_name']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['last_name']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['email']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['billing_address']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['shipping_address']));
|
||||
}
|
||||
|
||||
public function testSanitizeWithoutOptionalInBillingAddress()
|
||||
{
|
||||
$params = MtChargeFixture::build('vtweb');
|
||||
unset($params['customer_details']['billing_address']['first_name']);
|
||||
unset($params['customer_details']['billing_address']['last_name']);
|
||||
unset($params['customer_details']['billing_address']['phone']);
|
||||
unset($params['customer_details']['billing_address']['address']);
|
||||
unset($params['customer_details']['billing_address']['city']);
|
||||
unset($params['customer_details']['billing_address']['postal_code']);
|
||||
unset($params['customer_details']['billing_address']['country_code']);
|
||||
|
||||
Sanitizer::jsonRequest($params);
|
||||
|
||||
$this->assertEquals(false, isset($params['customer_details']['billing_address']['first_name']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['billing_address']['last_name']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['billing_address']['phone']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['billing_address']['address']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['billing_address']['city']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['billing_address']['postal_code']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['billing_address']['country_code']));
|
||||
}
|
||||
|
||||
public function testSanitizeWithoutOptionalInShippingAddress()
|
||||
{
|
||||
$params = MtChargeFixture::build('vtweb');
|
||||
unset($params['customer_details']['shipping_address']['first_name']);
|
||||
unset($params['customer_details']['shipping_address']['last_name']);
|
||||
unset($params['customer_details']['shipping_address']['phone']);
|
||||
unset($params['customer_details']['shipping_address']['address']);
|
||||
unset($params['customer_details']['shipping_address']['city']);
|
||||
unset($params['customer_details']['shipping_address']['postal_code']);
|
||||
unset($params['customer_details']['shipping_address']['country_code']);
|
||||
|
||||
Sanitizer::jsonRequest($params);
|
||||
|
||||
$this->assertEquals(false, isset($params['customer_details']['shipping_address']['first_name']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['shipping_address']['last_name']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['shipping_address']['phone']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['shipping_address']['address']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['shipping_address']['city']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['shipping_address']['postal_code']));
|
||||
$this->assertEquals(false, isset($params['customer_details']['shipping_address']['country_code']));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans;
|
||||
|
||||
class MidtransSnapApiRequestorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testConfigOptionsOverrideCurlOptions()
|
||||
{
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{ "status_code": "200" }';
|
||||
MT_Tests::$stubHttpStatus = array('http_code' => 201);
|
||||
|
||||
Config::$curlOptions = array(
|
||||
CURLOPT_HTTPHEADER => array( "User-Agent: testing lib" ),
|
||||
CURLOPT_PROXY => "http://proxy.com"
|
||||
);
|
||||
|
||||
$resp = ApiRequestor::post("http://example.com", "dummy", "");
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertTrue(in_array("User-Agent: testing lib", $fields["HTTPHEADER"]));
|
||||
$this->assertTrue(in_array('Content-Type: application/json', $fields["HTTPHEADER"]));
|
||||
|
||||
$this->assertEquals("http://proxy.com", $fields["PROXY"]);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
MT_Tests::reset();
|
||||
Config::$curlOptions = array();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans;
|
||||
|
||||
class MidtransSnapTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testGetSnapToken()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
Config::$appendNotifUrl = "https://example.com";
|
||||
Config::$overrideNotifUrl = "https://example.com";
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{ "token": "abcdefghijklmnopqrstuvwxyz" }';
|
||||
MT_Tests::$stubHttpStatus = array('http_code' => 201);
|
||||
|
||||
$params = array(
|
||||
'transaction_details' => array(
|
||||
'order_id' => "Order-111",
|
||||
'gross_amount' => 10000,
|
||||
)
|
||||
);
|
||||
|
||||
$tokenId = Snap::getSnapToken($params);
|
||||
|
||||
$this->assertEquals("abcdefghijklmnopqrstuvwxyz", $tokenId);
|
||||
|
||||
$this->assertEquals(
|
||||
"https://app.sandbox.midtrans.com/snap/v1/transactions",
|
||||
MT_Tests::$lastHttpRequest["url"]
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'MyVerySecretKey',
|
||||
MT_Tests::$lastHttpRequest["server_key"]
|
||||
);
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
|
||||
$this->assertEquals(1, $fields["POST"]);
|
||||
$this->assertTrue(in_array('X-Append-Notification: https://example.com', $fields["HTTPHEADER"]));
|
||||
$this->assertTrue(in_array('X-Override-Notification: https://example.com', $fields["HTTPHEADER"]));
|
||||
$this->assertEquals(
|
||||
$fields["POSTFIELDS"],
|
||||
'{"credit_card":{"secure":false},' .
|
||||
'"transaction_details":{"order_id":"Order-111","gross_amount":10000}}'
|
||||
);
|
||||
}
|
||||
|
||||
public function testGrossAmount()
|
||||
{
|
||||
$params = array(
|
||||
'transaction_details' => array(
|
||||
'order_id' => rand()
|
||||
),
|
||||
'item_details' => array( array( 'price' => 10000, 'quantity' => 5 ) )
|
||||
);
|
||||
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{ "token": "abcdefghijklmnopqrstuvwxyz" }';
|
||||
MT_Tests::$stubHttpStatus = array('http_code' => 201);
|
||||
|
||||
$tokenId = Snap::getSnapToken($params);
|
||||
|
||||
$this->assertEquals(
|
||||
50000,
|
||||
MT_Tests::$lastHttpRequest['data_hash']['transaction_details']['gross_amount']
|
||||
);
|
||||
}
|
||||
|
||||
public function testOverrideParams()
|
||||
{
|
||||
$params = array(
|
||||
'echannel' => array(
|
||||
'bill_info1' => 'bill_value1'
|
||||
)
|
||||
);
|
||||
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{ "token": "abcdefghijklmnopqrstuvwxyz" }';
|
||||
MT_Tests::$stubHttpStatus = array('http_code' => 201);
|
||||
|
||||
$tokenId = Snap::getSnapToken($params);
|
||||
|
||||
$this->assertEquals(
|
||||
array('bill_info1' => 'bill_value1'),
|
||||
MT_Tests::$lastHttpRequest['data_hash']['echannel']
|
||||
);
|
||||
}
|
||||
|
||||
public function testRealConnect()
|
||||
{
|
||||
$params = array(
|
||||
'transaction_details' => array(
|
||||
'order_id' => rand(),
|
||||
'gross_amount' => 10000,
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
$tokenId = Snap::getSnapToken($params);
|
||||
} catch (\Exception $error) {
|
||||
$errorHappen = true;
|
||||
$this->assertContains(
|
||||
"authorized",
|
||||
$error->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertTrue($errorHappen);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
MT_Tests::reset();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
namespace Midtrans;
|
||||
|
||||
class MidtransTransactionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testStatus()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code": "200",
|
||||
"status_message": "Success, transaction found",
|
||||
"transaction_id": "e3b8c383-55b4-4223-bd77-15c48c0245ca",
|
||||
"masked_card": "481111-1114",
|
||||
"order_id": "Order-111",
|
||||
"payment_type": "credit_card",
|
||||
"transaction_time": "2014-11-21 13:07:50",
|
||||
"transaction_status": "settlement",
|
||||
"fraud_status": "accept",
|
||||
"approval_code": "1416550071152",
|
||||
"signature_key": "4ef8218aad5b64bae2ec9d6b0f0a0b059b88bd...",
|
||||
"bank": "mandiri",
|
||||
"gross_amount": "10000.00"
|
||||
}';
|
||||
|
||||
$status = Transaction::status("Order-111");
|
||||
|
||||
$this->assertEquals("200", $status->status_code);
|
||||
$this->assertEquals("Order-111", $status->order_id);
|
||||
$this->assertEquals("1416550071152", $status->approval_code);
|
||||
|
||||
$this->assertEquals(
|
||||
"https://api.sandbox.midtrans.com/v2/Order-111/status",
|
||||
MT_Tests::$lastHttpRequest["url"]
|
||||
);
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertFalse(isset($fields['POST']));
|
||||
$this->assertFalse(isset($fields['POSTFIELDS']));
|
||||
}
|
||||
|
||||
public function testFailureStatus()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code": "404",
|
||||
"status_message": "The requested resource is not found"
|
||||
}';
|
||||
|
||||
try {
|
||||
$status = Transaction::status("Order-111");
|
||||
} catch (\Exception $error) {
|
||||
$errorHappen = true;
|
||||
$this->assertEquals(404, $error->getCode());
|
||||
}
|
||||
|
||||
$this->assertTrue($errorHappen);
|
||||
MT_Tests::reset();
|
||||
}
|
||||
|
||||
public function testRealStatus()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
try {
|
||||
$status = Transaction::status("Order-111");
|
||||
} catch (\Exception $error) {
|
||||
$errorHappen = true;
|
||||
$this->assertContains("Midtrans API is returning API error. HTTP status code: 401", $error->getMessage());
|
||||
}
|
||||
|
||||
$this->assertTrue($errorHappen);
|
||||
}
|
||||
|
||||
public function testApprove()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code": "200",
|
||||
"status_message": "Success, transaction is approved",
|
||||
"transaction_id": "2af158d4-b82e-46ac-808b-be19aaa96ce3",
|
||||
"masked_card": "451111-1117",
|
||||
"order_id": "Order-111",
|
||||
"payment_type": "credit_card",
|
||||
"transaction_time": "2014-11-27 10:05:10",
|
||||
"transaction_status": "capture",
|
||||
"fraud_status": "accept",
|
||||
"approval_code": "1416550071152",
|
||||
"bank": "bni",
|
||||
"gross_amount": "10000.00"
|
||||
}';
|
||||
|
||||
$approve = Transaction::approve("Order-111");
|
||||
|
||||
$this->assertEquals("200", $approve);
|
||||
|
||||
$this->assertEquals(
|
||||
"https://api.sandbox.midtrans.com/v2/Order-111/approve",
|
||||
MT_Tests::$lastHttpRequest["url"]
|
||||
);
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertEquals(1, $fields["POST"]);
|
||||
$this->assertEquals(null, $fields["POSTFIELDS"]);
|
||||
}
|
||||
|
||||
public function testCancel()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code": "200",
|
||||
"status_message": "Success, transaction is canceled",
|
||||
"transaction_id": "2af158d4-b82e-46ac-808b-be19aaa96ce3",
|
||||
"masked_card": "451111-1117",
|
||||
"order_id": "Order-111",
|
||||
"payment_type": "credit_card",
|
||||
"transaction_time": "2014-11-27 10:05:10",
|
||||
"transaction_status": "cancel",
|
||||
"fraud_status": "accept",
|
||||
"approval_code": "1416550071152",
|
||||
"bank": "bni",
|
||||
"gross_amount": "10000.00"
|
||||
}';
|
||||
|
||||
$cancel = Transaction::cancel("Order-111");
|
||||
|
||||
$this->assertEquals("200", $cancel);
|
||||
|
||||
$this->assertEquals(
|
||||
"https://api.sandbox.midtrans.com/v2/Order-111/cancel",
|
||||
MT_Tests::$lastHttpRequest["url"]
|
||||
);
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertEquals(1, $fields["POST"]);
|
||||
$this->assertEquals(null, $fields["POSTFIELDS"]);
|
||||
}
|
||||
|
||||
public function testExpire()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code": "407",
|
||||
"status_message": "Success, transaction has expired",
|
||||
"transaction_id": "2af158d4-b82e-46ac-808b-be19aaa96ce3",
|
||||
"order_id": "Order-111",
|
||||
"payment_type": "echannel",
|
||||
"transaction_time": "2014-11-27 10:05:10",
|
||||
"transaction_status": "expire",
|
||||
"gross_amount": "10000.00"
|
||||
}';
|
||||
|
||||
$expire = Transaction::expire("Order-111");
|
||||
|
||||
$this->assertEquals("407", $expire->status_code);
|
||||
$this->assertEquals("Success, transaction has expired", $expire->status_message);
|
||||
|
||||
$this->assertEquals(
|
||||
"https://api.sandbox.midtrans.com/v2/Order-111/expire",
|
||||
MT_Tests::$lastHttpRequest["url"]
|
||||
);
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertEquals(1, $fields["POST"]);
|
||||
$this->assertEquals(null, $fields["POSTFIELDS"]);
|
||||
}
|
||||
|
||||
public function testRefund()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code": "200",
|
||||
"status_message": "Success, refund request is approved",
|
||||
"transaction_id": "447e846a-403e-47db-a5da-d7f3f06375d6",
|
||||
"order_id": "Order-111",
|
||||
"payment_type": "credit_card",
|
||||
"transaction_time": "2015-06-15 13:36:24",
|
||||
"transaction_status": "refund",
|
||||
"gross_amount": "10000.00",
|
||||
"refund_chargeback_id": 1,
|
||||
"refund_amount": "10000.00",
|
||||
"refund_key": "reference1"
|
||||
}';
|
||||
|
||||
$params = array(
|
||||
'refund_key' => 'reference1',
|
||||
'amount' => 10000,
|
||||
'reason' => 'Item out of stock'
|
||||
);
|
||||
$refund = Transaction::refund("Order-111",$params);
|
||||
|
||||
$this->assertEquals("200", $refund->status_code);
|
||||
|
||||
$this->assertEquals(
|
||||
"https://api.sandbox.midtrans.com/v2/Order-111/refund",
|
||||
MT_Tests::$lastHttpRequest["url"]
|
||||
);
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertEquals(1, $fields["POST"]);
|
||||
$this->assertEquals(
|
||||
'{"refund_key":"reference1","amount":10000,"reason":"Item out of stock"}',
|
||||
$fields["POSTFIELDS"]);
|
||||
}
|
||||
|
||||
public function testRefundDirect()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code": "200",
|
||||
"status_message": "Success, refund request is approved",
|
||||
"transaction_id": "447e846a-403e-47db-a5da-d7f3f06375d6",
|
||||
"order_id": "Order-111",
|
||||
"payment_type": "credit_card",
|
||||
"transaction_time": "2015-06-15 13:36:24",
|
||||
"transaction_status": "refund",
|
||||
"gross_amount": "10000.00",
|
||||
"refund_chargeback_id": 1,
|
||||
"refund_amount": "10000.00",
|
||||
"refund_key": "reference1"
|
||||
}';
|
||||
|
||||
$params = array(
|
||||
'refund_key' => 'reference1',
|
||||
'amount' => 10000,
|
||||
'reason' => 'Item out of stock'
|
||||
);
|
||||
$refund = Transaction::refundDirect("Order-111", $params);
|
||||
$this->assertEquals("200", $refund->status_code);
|
||||
|
||||
$this->assertEquals(
|
||||
"https://api.sandbox.midtrans.com/v2/Order-111/refund/online/direct",
|
||||
MT_Tests::$lastHttpRequest["url"]
|
||||
);
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertEquals(1, $fields["POST"]);
|
||||
$this->assertEquals(
|
||||
'{"refund_key":"reference1","amount":10000,"reason":"Item out of stock"}',
|
||||
$fields["POSTFIELDS"]);
|
||||
}
|
||||
|
||||
public function testDeny()
|
||||
{
|
||||
Config::$serverKey = 'MyVerySecretKey';
|
||||
MT_Tests::$stubHttp = true;
|
||||
MT_Tests::$stubHttpResponse = '{
|
||||
"status_code" : "200",
|
||||
"status_message" : "Success, transaction is denied",
|
||||
"transaction_id" : "ca297170-be4c-45ed-9dc9-be5ba99d30ee",
|
||||
"masked_card" : "451111-1117",
|
||||
"order_id" : "Order-111",
|
||||
"payment_type" : "credit_card",
|
||||
"transaction_time" : "2014-10-31 14:46:44",
|
||||
"transaction_status" : "deny",
|
||||
"fraud_status" : "deny",
|
||||
"bank" : "bni",
|
||||
"gross_amount" : "30000.00"
|
||||
}';
|
||||
|
||||
$deny = Transaction::deny("Order-111");
|
||||
|
||||
$this->assertEquals("200", $deny->status_code);
|
||||
|
||||
$this->assertEquals(
|
||||
"https://api.sandbox.midtrans.com/v2/Order-111/deny",
|
||||
MT_Tests::$lastHttpRequest["url"]
|
||||
);
|
||||
|
||||
$fields = MT_Tests::lastReqOptions();
|
||||
$this->assertEquals(1, $fields["POST"]);
|
||||
$this->assertEquals(null, $fields["POSTFIELDS"]);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
MT_Tests::reset();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans\integration;
|
||||
|
||||
use Midtrans\CoreApi;
|
||||
use Midtrans\utility\MtChargeFixture;
|
||||
|
||||
require_once 'IntegrationTest.php';
|
||||
|
||||
class CoreApiIntegrationTest extends IntegrationTest
|
||||
{
|
||||
private $payment_type;
|
||||
private $charge_params;
|
||||
private $charge_response;
|
||||
|
||||
public function prepareChargeParams($payment_type, $payment_data = null)
|
||||
{
|
||||
$this->payment_type = $payment_type;
|
||||
$this->charge_params = MtChargeFixture::build($payment_type, $payment_data);
|
||||
}
|
||||
|
||||
public function testCardRegister()
|
||||
{
|
||||
$this->charge_response = CoreApi::cardRegister("4811111111111114", "12", "2026");
|
||||
$this->assertEquals('200', $this->charge_response->status_code);
|
||||
}
|
||||
|
||||
public function testCardToken()
|
||||
{
|
||||
$this->charge_response = CoreApi::cardToken("4811111111111114", "12", "2026", "123");
|
||||
$this->assertEquals('200', $this->charge_response->status_code);
|
||||
}
|
||||
|
||||
public function testCardPointInquiry()
|
||||
{
|
||||
$this->charge_response = CoreApi::cardToken("4617006959746656", "12", "2026", "123");
|
||||
$cardPointResponse = CoreApi::cardPointInquiry($this->charge_response->token_id);
|
||||
$this->assertEquals('200', $cardPointResponse->status_code);
|
||||
}
|
||||
|
||||
public function testChargeCimbClicks()
|
||||
{
|
||||
$this->prepareChargeParams(
|
||||
'cimb_clicks',
|
||||
array(
|
||||
"description" => "Item Descriptions",
|
||||
)
|
||||
);
|
||||
$this->charge_response = CoreApi::charge($this->charge_params);
|
||||
$this->assertEquals('pending', $this->charge_response->transaction_status);
|
||||
$this->assertTrue(isset($this->charge_response->redirect_url));
|
||||
}
|
||||
|
||||
public function testChargePermataVa()
|
||||
{
|
||||
$this->prepareChargeParams(
|
||||
'bank_transfer',
|
||||
array(
|
||||
"bank" => "permata",
|
||||
)
|
||||
);
|
||||
$this->charge_response = CoreApi::charge($this->charge_params);
|
||||
$this->assertEquals('pending', $this->charge_response->transaction_status);
|
||||
$this->assertTrue(isset($this->charge_response->permata_va_number));
|
||||
}
|
||||
|
||||
public function testChargeEPayBri()
|
||||
{
|
||||
$this->prepareChargeParams('bri_epay');
|
||||
$this->charge_response = CoreApi::charge($this->charge_params);
|
||||
$this->assertEquals('pending', $this->charge_response->transaction_status);
|
||||
$this->assertTrue(isset($this->charge_response->redirect_url));
|
||||
}
|
||||
|
||||
public function testChargeMandiriBillPayment()
|
||||
{
|
||||
$this->prepareChargeParams(
|
||||
'echannel',
|
||||
array(
|
||||
"bill_info1" => "Payment for:",
|
||||
"bill_info2" => "Item descriptions",
|
||||
)
|
||||
);
|
||||
$this->charge_response = CoreApi::charge($this->charge_params);
|
||||
$this->assertEquals('pending', $this->charge_response->transaction_status);
|
||||
}
|
||||
|
||||
public function testChargeIndomaret()
|
||||
{
|
||||
$this->prepareChargeParams(
|
||||
'cstore',
|
||||
array(
|
||||
"store" => "indomaret",
|
||||
"message" => "Item descriptions",
|
||||
)
|
||||
);
|
||||
$this->charge_response = CoreApi::charge($this->charge_params);
|
||||
$this->assertEquals('pending', $this->charge_response->transaction_status);
|
||||
$this->assertTrue(isset($this->charge_response->payment_code));
|
||||
}
|
||||
|
||||
public function testChargeGopay()
|
||||
{
|
||||
$this->prepareChargeParams(
|
||||
'gopay',
|
||||
array(
|
||||
"enable_callback" => true,
|
||||
"callback_url" => "someapps://callback",
|
||||
)
|
||||
);
|
||||
$this->charge_response = CoreApi::charge($this->charge_params);
|
||||
$this->assertEquals('201', $this->charge_response->status_code);
|
||||
$this->assertEquals('pending', $this->charge_response->transaction_status);
|
||||
}
|
||||
|
||||
public function testCreateSubscription()
|
||||
{
|
||||
$param = array(
|
||||
"name" => "Monthly_2021",
|
||||
"amount" => "10000",
|
||||
"currency" => "IDR",
|
||||
"payment_type" => "credit_card",
|
||||
"token" => "dummy",
|
||||
"schedule" => array(
|
||||
"interval" => 1,
|
||||
"interval_unit" => "month",
|
||||
"max_interval" => "12",
|
||||
"start_time" => "2022-08-17 10:00:01 +0700"
|
||||
),
|
||||
"metadata" => array(
|
||||
"description" => "Recurring payment for user a"
|
||||
),
|
||||
"customer_details" => array(
|
||||
"first_name" => "John",
|
||||
"last_name" => "Doe",
|
||||
"email" => "johndoe@gmail.com",
|
||||
"phone_number" => "+628987654321"
|
||||
)
|
||||
);
|
||||
$this->charge_response = CoreApi::createSubscription($param);
|
||||
$this->assertEquals('active', $this->charge_response->status);
|
||||
$subscription_id = $this->charge_response->id;
|
||||
return $subscription_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateSubscription
|
||||
*/
|
||||
public function testGetSubscription($subscription_id)
|
||||
{
|
||||
$this->charge_response = CoreApi::getSubscription($subscription_id);
|
||||
$this->assertEquals('active', $this->charge_response->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateSubscription
|
||||
*/
|
||||
public function testDisableSubscription($subscription_id)
|
||||
{
|
||||
$this->charge_response = CoreApi::disableSubscription($subscription_id);
|
||||
$this->assertContains('Subscription is updated.', $this->charge_response->status_message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateSubscription
|
||||
*/
|
||||
public function testEnableSubscription($subscription_id)
|
||||
{
|
||||
$this->charge_response = CoreApi::enableSubscription($subscription_id);
|
||||
$this->assertContains('Subscription is updated.', $this->charge_response->status_message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateSubscription
|
||||
*/
|
||||
public function testUpdateSubscription($subscription_id)
|
||||
{
|
||||
$param = array(
|
||||
"name" => "Monthly_2021",
|
||||
"amount" => "25000",
|
||||
"currency" => "IDR",
|
||||
"token" => "dummy",
|
||||
"schedule" => array(
|
||||
"interval" => 1
|
||||
)
|
||||
);
|
||||
|
||||
$this->charge_response = CoreApi::updateSubscription($subscription_id, $param);
|
||||
$this->assertContains('Subscription is updated.', $this->charge_response->status_message);
|
||||
}
|
||||
|
||||
public function testGetSubscriptionWithNonExistAccount()
|
||||
{
|
||||
try {
|
||||
$this->charge_response = CoreApi::getSubscription("dummy");
|
||||
} catch (\Exception $e) {
|
||||
$this->assertContains("Midtrans API is returning API error.", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testDisableSubscriptionWithNonExistAccount()
|
||||
{
|
||||
try {
|
||||
$this->charge_response = CoreApi::disableSubscription("dummy");
|
||||
} catch (\Exception $e) {
|
||||
$this->assertContains("Midtrans API is returning API error.", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testEnableSubscriptionWithNonExistAccount()
|
||||
{
|
||||
try {
|
||||
$this->charge_response = CoreApi::enableSubscription("dummy");
|
||||
} catch (\Exception $e) {
|
||||
$this->assertContains("Midtrans API is returning API error.", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testUpdateSubscriptionWithNonExistAccount()
|
||||
{
|
||||
$param = array(
|
||||
"name" => "Monthly_2021",
|
||||
"amount" => "25000",
|
||||
"currency" => "IDR",
|
||||
"token" => "dummy",
|
||||
"schedule" => array(
|
||||
"interval" => 1
|
||||
)
|
||||
);
|
||||
|
||||
try {
|
||||
$this->charge_response = CoreApi::updateSubscription("dummy", $param);
|
||||
} catch (\Exception $e) {
|
||||
$this->assertContains("Midtrans API is returning API error.", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testCreatePayAccount()
|
||||
{
|
||||
$params = array(
|
||||
"payment_type" => "gopay",
|
||||
"gopay_partner" => array(
|
||||
"phone_number" => 874567446788,
|
||||
"redirect_url" => "https://www.google.com"
|
||||
)
|
||||
);
|
||||
$this->charge_response = CoreApi::linkPaymentAccount($params);
|
||||
$this->assertEquals('201', $this->charge_response->status_code);
|
||||
$this->assertEquals('PENDING', $this->charge_response->account_status);
|
||||
$account_id = $this->charge_response->account_id;
|
||||
return $account_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreatePayAccount
|
||||
*/
|
||||
public function testGetPaymentAccount($account_id)
|
||||
{
|
||||
$this->charge_response = CoreApi::getPaymentAccount($account_id);
|
||||
$this->assertEquals('201', $this->charge_response->status_code);
|
||||
$this->assertEquals('PENDING', $this->charge_response->account_status);
|
||||
}
|
||||
|
||||
|
||||
public function testGetPaymentAccountWithNonExistAccount()
|
||||
{
|
||||
try {
|
||||
$this->charge_response = CoreApi::getPaymentAccount("dummy");
|
||||
} catch (\Exception $e) {
|
||||
$this->assertContains("Midtrans API is returning API error.", $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function testUnlinkPaymentAccountWithNonExistAccount()
|
||||
{
|
||||
try {
|
||||
$this->charge_response = CoreApi::unlinkPaymentAccount("dummy");
|
||||
} catch (\Exception $e) {
|
||||
$this->assertContains("Account doesn't exist.", $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans\integration;
|
||||
|
||||
use Midtrans\Config;
|
||||
|
||||
abstract class IntegrationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
Config::$serverKey = getenv('SERVER_KEY');
|
||||
Config::$clientKey = getenv('CLIENT_KEY');
|
||||
Config::$isProduction = false;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
// One second interval to avoid throttle
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans\integration;
|
||||
|
||||
use Midtrans\CoreApi;
|
||||
use Midtrans\Notification;
|
||||
use Midtrans\Transaction;
|
||||
use Midtrans\utility\MtChargeFixture;
|
||||
|
||||
require_once 'IntegrationTest.php';
|
||||
|
||||
|
||||
class NotificationIntegrationTest extends IntegrationTest
|
||||
{
|
||||
private $status_response;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$charge_params = MtChargeFixture::build('bri_epay');
|
||||
$charge_response = CoreApi::charge($charge_params);
|
||||
$this->status_response = Transaction::status($charge_response->transaction_id);
|
||||
}
|
||||
|
||||
public function testValidBriEPayNotification()
|
||||
{
|
||||
// Assume status response is similar to HTTP(s) notification
|
||||
$tmpfname = tempnam(sys_get_temp_dir(), "test");
|
||||
file_put_contents($tmpfname, json_encode($this->status_response));
|
||||
|
||||
$notif = new Notification($tmpfname);
|
||||
|
||||
$this->assertEquals($notif->status_code, "201");
|
||||
$this->assertEquals($notif->transaction_status, "pending");
|
||||
$this->assertEquals($notif->payment_type, "bri_epay");
|
||||
$this->assertEquals($notif->order_id, $this->status_response->order_id);
|
||||
$this->assertEquals($notif->transaction_id, $this->status_response->transaction_id);
|
||||
$this->assertEquals($notif->gross_amount, $this->status_response->gross_amount);
|
||||
|
||||
unlink($tmpfname);
|
||||
}
|
||||
|
||||
public function testFraudulentBriEPayNotification()
|
||||
{
|
||||
/*
|
||||
As a fraudster, I want the merchant to think that I finished e-Pay BRI payment
|
||||
1. alter transaction status, from pending to settlement
|
||||
2. alter status code, from 201 to 200
|
||||
*/
|
||||
$this->status_response->transaction_status = "settlement";
|
||||
$this->status_response->status_code = "200";
|
||||
|
||||
$tmpfname = tempnam(sys_get_temp_dir(), "test");
|
||||
file_put_contents($tmpfname, json_encode($this->status_response));
|
||||
|
||||
$notif = new Notification($tmpfname);
|
||||
|
||||
/*
|
||||
Merchant should not be tricked... thanks to Get Status API
|
||||
*/
|
||||
$this->assertEquals("201", $notif->status_code);
|
||||
$this->assertEquals("pending", $notif->transaction_status);
|
||||
$this->assertEquals("bri_epay", $notif->payment_type);
|
||||
$this->assertEquals($this->status_response->order_id, $notif->order_id);
|
||||
$this->assertEquals($this->status_response->transaction_id, $notif->transaction_id);
|
||||
$this->assertEquals($this->status_response->gross_amount, $notif->gross_amount);
|
||||
|
||||
unlink($tmpfname);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans\integration;
|
||||
|
||||
use Midtrans\Snap;
|
||||
use Midtrans\utility\MtChargeFixture;
|
||||
|
||||
require_once 'IntegrationTest.php';
|
||||
|
||||
class SnapIntegrationTest extends IntegrationTest
|
||||
{
|
||||
public function testSnapToken()
|
||||
{
|
||||
$charge_params = MtChargeFixture::build('vtweb');
|
||||
$token_id = Snap::getSnapToken($charge_params);
|
||||
|
||||
$this->assertTrue(isset($token_id));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans\integration;
|
||||
|
||||
use Midtrans\CoreApi;
|
||||
use Midtrans\Transaction;
|
||||
use Midtrans\utility\MtChargeFixture;
|
||||
|
||||
require_once 'IntegrationTest.php';
|
||||
|
||||
class TransactionIntegrationTest extends IntegrationTest
|
||||
{
|
||||
|
||||
public function testStatusPermataVa()
|
||||
{
|
||||
$charge_params = MtChargeFixture::build(
|
||||
'bank_transfer',
|
||||
array(
|
||||
"bank" => "permata",
|
||||
)
|
||||
);
|
||||
$charge_response = CoreApi::charge($charge_params);
|
||||
$status_response = Transaction::status($charge_response->transaction_id);
|
||||
|
||||
$this->assertEquals('201', $status_response->status_code);
|
||||
$this->assertEquals('pending', $status_response->transaction_status);
|
||||
$this->assertEquals($charge_params['transaction_details']['order_id'], $status_response->order_id);
|
||||
$this->assertEquals($charge_params['transaction_details']['gross_amount'], $status_response->gross_amount);
|
||||
$this->assertEquals($charge_response->transaction_id, $status_response->transaction_id);
|
||||
$this->assertEquals($charge_response->transaction_time, $status_response->transaction_time);
|
||||
$this->assertEquals('Success, transaction is found', $status_response->status_message);
|
||||
|
||||
$this->assertTrue(isset($status_response->signature_key));
|
||||
}
|
||||
|
||||
public function testCancelPermataVa()
|
||||
{
|
||||
$charge_params = MtChargeFixture::build(
|
||||
'bank_transfer',
|
||||
array(
|
||||
"bank" => "permata",
|
||||
)
|
||||
);
|
||||
$charge_response = CoreApi::charge($charge_params);
|
||||
$cancel_status_code = Transaction::cancel($charge_response->transaction_id);
|
||||
|
||||
$this->assertEquals('200', $cancel_status_code);
|
||||
}
|
||||
|
||||
public function testExpirePermataVa()
|
||||
{
|
||||
$charge_params = MtChargeFixture::build(
|
||||
'bank_transfer',
|
||||
array(
|
||||
"bank" => "permata",
|
||||
)
|
||||
);
|
||||
$charge_response = CoreApi::charge($charge_params);
|
||||
$expire = Transaction::expire($charge_response->transaction_id);
|
||||
|
||||
$this->assertEquals('407', $expire->status_code);
|
||||
|
||||
// Verify transaction via API
|
||||
$txn_status = Transaction::status($charge_response->transaction_id);
|
||||
$this->assertEquals("407", $txn_status->status_code);
|
||||
$this->assertEquals("expire", $txn_status->transaction_status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Midtrans\utility;
|
||||
|
||||
class MtFixture
|
||||
{
|
||||
protected static function readFixture($filename)
|
||||
{
|
||||
$charge_json = file_get_contents(__DIR__ . '/fixture/' . $filename);
|
||||
$charge_template_params = json_decode($charge_json, true);
|
||||
$charge_template_params['transaction_details']['order_id'] = rand();
|
||||
return $charge_template_params;
|
||||
}
|
||||
}
|
||||
|
||||
class MtChargeFixture extends MtFixture
|
||||
{
|
||||
public static function build($payment_type, $payment_data = null)
|
||||
{
|
||||
$charge_params = self::readFixture('mt_charge.json');
|
||||
|
||||
if (!is_null($payment_type)) {
|
||||
$charge_params['payment_type'] = $payment_type;
|
||||
}
|
||||
|
||||
if (!is_null($payment_data)) {
|
||||
$charge_params[$payment_type] = $payment_data;
|
||||
}
|
||||
return $charge_params;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"transaction_details": {
|
||||
"order_id": "C17550",
|
||||
"gross_amount": 145000
|
||||
},
|
||||
|
||||
"item_details" : [
|
||||
{
|
||||
"id": "a1",
|
||||
"price": 50000,
|
||||
"quantity": 2,
|
||||
"name": "Apel"
|
||||
},
|
||||
{
|
||||
"id": "a2",
|
||||
"price": 45000,
|
||||
"quantity": 1,
|
||||
"name": "Jeruk"
|
||||
}
|
||||
],
|
||||
"customer_details": {
|
||||
"first_name": "Andri",
|
||||
"last_name": "Litani",
|
||||
"email": "andri@litani.com",
|
||||
"phone": "081122334455",
|
||||
"billing_address": {
|
||||
"first_name": "Andri",
|
||||
"last_name": "Litani",
|
||||
"address": "Mangga 20",
|
||||
"city": "Jakarta",
|
||||
"postal_code": "16602",
|
||||
"phone": "081122334455",
|
||||
"country_code": "IDN"
|
||||
},
|
||||
"shipping_address": {
|
||||
"first_name": "Obet",
|
||||
"last_name": "Supriadi",
|
||||
"address": "Manggis 90",
|
||||
"city": "Jakarta",
|
||||
"postal_code": "16601",
|
||||
"phone": "08113366345",
|
||||
"country_code": "IDN"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user