Skip to content

Commit

Permalink
Merge pull request #57 from Andrenzo17/master
Browse files Browse the repository at this point in the history
- Hotfix cannot get transaction status
- update base url
  • Loading branch information
Andrenzo17 authored Aug 23, 2021
2 parents 222db12 + 25ff063 commit a1ad0c8
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion Midtrans/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function remoteCall($url, $server_key, $data_hash, $method)
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Accept: application/json',
'User-Agent: midtrans-php-v2.5.0',
'User-Agent: midtrans-php-v2.5.2',
'Authorization: Basic ' . base64_encode($server_key . ':')
),
CURLOPT_RETURNTRANSFER => 1
Expand Down
8 changes: 4 additions & 4 deletions Midtrans/CoreApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static function createSubscription($param)
}

/**
* Do `/v1/subscription/{subscription_id}` API request to Core API
* Do `/v1/subscription/<subscription_id>` API request to Core API
*
* @param string get subscription request (more params detail refer to: https://api-docs.midtrans.com/#get-subscription)
* @return mixed
Expand All @@ -208,7 +208,7 @@ public static function getSubscription($SubscriptionId)
}

/**
* Do disable `/v1/subscription/{subscription_id}/disable` API request to Core API
* Do disable `/v1/subscription/<subscription_id>/disable` API request to Core API
*
* @param string disable subscription request (more params detail refer to: https://api-docs.midtrans.com/#disable-subscription)
* @return mixed
Expand All @@ -224,7 +224,7 @@ public static function disableSubscription($SubscriptionId)
}

/**
* Do enable `/v1/subscription/{subscription_id}/enable` API request to Core API
* Do enable `/v1/subscription/<subscription_id>/enable` API request to Core API
*
* @param string enable subscription request (more params detail refer to: https://api-docs.midtrans.com/#enable-subscription)
* @return mixed
Expand All @@ -240,7 +240,7 @@ public static function enableSubscription($SubscriptionId)
}

/**
* Do update subscription `/v1/subscription/{subscription_id}` API request to Core API
* Do update subscription `/v1/subscription/<subscription_id>` API request to Core API
*
* @param string update subscription request (more params detail refer to: https://api-docs.midtrans.com/#update-subscription)
* @return mixed
Expand Down
16 changes: 8 additions & 8 deletions Midtrans/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Transaction
public static function status($id)
{
return ApiRequestor::get(
Config::getBaseUrl() . '/' . $id . '/status',
Config::getBaseUrl() . '/v2/' . $id . '/status',
Config::$serverKey,
false
);
Expand All @@ -37,7 +37,7 @@ public static function status($id)
public static function statusB2b($id)
{
return ApiRequestor::get(
Config::getBaseUrl() . '/' . $id . '/status/b2b',
Config::getBaseUrl() . '/v2/' . $id . '/status/b2b',
Config::$serverKey,
false
);
Expand All @@ -54,7 +54,7 @@ public static function statusB2b($id)
public static function approve($id)
{
return ApiRequestor::post(
Config::getBaseUrl() . '/' . $id . '/approve',
Config::getBaseUrl() . '/v2/' . $id . '/approve',
Config::$serverKey,
false
)->status_code;
Expand All @@ -71,7 +71,7 @@ public static function approve($id)
public static function cancel($id)
{
return ApiRequestor::post(
Config::getBaseUrl() . '/' . $id . '/cancel',
Config::getBaseUrl() . '/v2/' . $id . '/cancel',
Config::$serverKey,
false
)->status_code;
Expand All @@ -88,7 +88,7 @@ public static function cancel($id)
public static function expire($id)
{
return ApiRequestor::post(
Config::getBaseUrl() . '/' . $id . '/expire',
Config::getBaseUrl() . '/v2/' . $id . '/expire',
Config::$serverKey,
false
);
Expand All @@ -108,7 +108,7 @@ public static function expire($id)
public static function refund($id, $params)
{
return ApiRequestor::post(
Config::getBaseUrl() . '/' . $id . '/refund',
Config::getBaseUrl() . '/v2/' . $id . '/refund',
Config::$serverKey,
$params
);
Expand All @@ -127,7 +127,7 @@ public static function refund($id, $params)
public static function refundDirect($id, $params)
{
return ApiRequestor::post(
Config::getBaseUrl() . '/' . $id . '/refund/online/direct',
Config::getBaseUrl() . '/v2/' . $id . '/refund/online/direct',
Config::$serverKey,
$params
);
Expand All @@ -145,7 +145,7 @@ public static function refundDirect($id, $params)
public static function deny($id)
{
return ApiRequestor::post(
Config::getBaseUrl() . '/' . $id . '/deny',
Config::getBaseUrl() . '/v2/' . $id . '/deny',
Config::$serverKey,
false
);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "midtrans/midtrans-php",
"description": "PHP Wrapper for Midtrans Payment API.",
"homepage": "https://midtrans.com",
"version": "2.5.0",
"version": "2.5.2",
"type": "library",
"license":"MIT",
"authors": [
Expand Down
146 changes: 73 additions & 73 deletions tests/integration/CoreApiIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,51 +113,6 @@ public function testChargeGopay()
$this->assertEquals('pending', $this->charge_response->transaction_status);
}

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());
}
}

public function testCreateSubscription()
{
$param = array(
Expand Down Expand Up @@ -197,15 +152,6 @@ public function testGetSubscription($subscription_id)
$this->assertEquals('active', $this->charge_response->status);
}

public function testGetSubscriptionWithNonExistAccount()
{
try {
$this->charge_response = CoreApi::getSubscription("dummy");
} catch (\Exception $e) {
$this->assertContains("Subscription doesn't exist.", $e->getMessage());
}
}

/**
* @depends testCreateSubscription
*/
Expand All @@ -215,15 +161,6 @@ public function testDisableSubscription($subscription_id)
$this->assertContains('Subscription is updated.', $this->charge_response->status_message);
}

public function testDisableSubscriptionWithNonExistAccount()
{
try {
$this->charge_response = CoreApi::disableSubscription("dummy");
} catch (\Exception $e) {
$this->assertContains("Subscription doesn't exist.", $e->getMessage());
}
}

/**
* @depends testCreateSubscription
*/
Expand All @@ -233,15 +170,6 @@ public function testEnableSubscription($subscription_id)
$this->assertContains('Subscription is updated.', $this->charge_response->status_message);
}

public function testEnableSubscriptionWithNonExistAccount()
{
try {
$this->charge_response = CoreApi::enableSubscription("dummy");
} catch (\Exception $e) {
$this->assertContains("Subscription doesn't exist.", $e->getMessage());
}
}

/**
* @depends testCreateSubscription
*/
Expand All @@ -261,6 +189,33 @@ public function testUpdateSubscription($subscription_id)
$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(
Expand All @@ -276,7 +231,52 @@ public function testUpdateSubscriptionWithNonExistAccount()
try {
$this->charge_response = CoreApi::updateSubscription("dummy", $param);
} catch (\Exception $e) {
$this->assertContains("Subscription doesn't exist.", $e->getMessage());
$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 comments on commit a1ad0c8

Please sign in to comment.