[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: MidtransCoreApiTest.php
<?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(); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.68 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002