Skip to content

Commit

Permalink
Merge pull request #3 from salman-mahmood/main
Browse files Browse the repository at this point in the history
Test cases implemented for direct checkout
  • Loading branch information
zfhassaan authored May 26, 2023
2 parents 8788f16 + 6e30191 commit 00f973e
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/EasyPaisaServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ class EasyPaisaServiceProvider extends ServiceProvider
*/
public function boot() {
if($this->app->runningInConsole()) {

$this->publishes([
__DIR__.'/../config/config.php'=>config_path('easypaisa.php'),
],'config');
$this->publishes([
__DIR__.'/../tests'=>base_path('tests'),
], 'tests');
}
}

Expand All @@ -31,4 +35,4 @@ public function register()
return new Easypaisa;
});
}
}
}
17 changes: 16 additions & 1 deletion src/Easypaisa.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateTime;
use DateTimeZone;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
Expand All @@ -19,7 +20,15 @@ class Easypaisa extends Payment
*/
public function sendRequest($request)
{
$credentials = $this->getCredentials();
try{
$email = $request['emailAddress'];
if (intval($request['transactionAmount']) < 0 || empty($request['orderId']) || empty($request['mobileAccountNo'])) {
return response()->json(['status' => false, 'message' => 'Invalid Arguments Passed'], Response::HTTP_CONFLICT);
}
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
return response()->json(['status' => false, 'message' => 'Email format is incorrect'], Response::HTTP_CONFLICT);
}
$credentials = $this->getCredentials();

$data = [
'orderId'=> strip_tags($request['orderId']),
Expand All @@ -37,6 +46,12 @@ public function sendRequest($request)

$result = $response->json();
return $result;
}
catch(\Exception $e)
{
return response()->json(['status'=> false, 'message'=>$e->getMessage()], Response::HTTP_INTERNAL_SERVER_ERROR);
}

}

/**
Expand Down
141 changes: 141 additions & 0 deletions tests/unit/EasypaisaDirectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Support\Str;
use Zfhassaan\Easypaisa\Easypaisa;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\JsonResponse;

class EasypaisaDirectTest extends TestCase
{
/**
* Test sending a Direct Request with valid data.
*/
public function testSendDirectRequestWithValidData()
{
// Data
$requestData = [
'orderId'=> '548828745',
'transactionAmount' => 10,
'mobileAccountNo' => '03450975945',
'emailAddress' => 'abc@gmail.com'
];
$easypaisa = new Easypaisa();
// Action
$result = $easypaisa->sendRequest($requestData);
$expectedUrl = 'https://easypaystg.easypaisa.com.pk';
$this->assertTrue(Str::contains($result, $expectedUrl));
}
/**
* Test Sending a Direct Request with missing orderId
*/
public function testSendDirectRequestWithMissingOrderid()
{
// Data
$requestData = [
'transactionAmount' => 10,
'mobileAccountNo' => '03450975945',
'emailAddress' => 'abc@gmail.com'
];
$easypaisa = new Easypaisa();
// Action
$result = $easypaisa->sendRequest($requestData);
$this->assertInstanceOf(JsonResponse::class, $result);
}
/**
* Test Sending a Direct Request with missing transectionAmount
*/
public function testSendDirectRequestWithMissingTransactionAmount()
{
// Data
$requestData = [
'orderId'=> '548828745',
'mobileAccountNo' => '03450975945',
'emailAddress' => 'abc@gmail.com'
];
$easypaisa = new Easypaisa();
// Action
$result = $easypaisa->sendRequest($requestData);
$this->assertInstanceOf(JsonResponse::class, $result);
}
/**
* Test Sending a Direct Request with missing mobileAccountNo
*/
public function testSendDirectRequestWithMissingMobileAccountNo()
{
// Data
$requestData = [
'orderId'=> '548828745',
'transactionAmount' => 10,
'emailAddress' => 'abc@gmail.com'
];
$easypaisa = new Easypaisa();
// Action
$result = $easypaisa->sendRequest($requestData);
$this->assertInstanceOf(JsonResponse::class, $result);
}
/**
* Test Sending a Direct Request with missing emailAddress
*/
public function testSendDirectRequestWithMissingEmailAddress()
{
// Data
$requestData = [
'orderId'=> '548828745',
'transactionAmount' => 10,
'mobileAccountNo' => '03450975945'
];
$easypaisa = new Easypaisa();
// Action
$result = $easypaisa->sendRequest($requestData);
$this->assertInstanceOf(JsonResponse::class, $result);
}
/**
* Test Sending a Direct Request with invalid transactionAmount
*/
public function testSendDirectRequestWithInvalidTransactionAmount()
{
// Data
$requestData = [
'orderId'=> '548828745',
'transactionAmount' => -1,
'mobileAccountNo' => '03450975945',
'emailAddress' => 'abc@gmail.com'
];
$easypaisa = new Easypaisa();
// Action
$result = $easypaisa->sendRequest($requestData);
$this->assertInstanceOf(JsonResponse::class, $result);
}
public function testSendDirectRequestWithInvalidEmailAddress()
{
// Data
$requestData = [
'orderId'=> '548828745',
'transactionAmount' => 10,
'mobileAccountNo' => '03450975945',
'emailAddress' => 'abcgmail.com'
];
$easypaisa = new Easypaisa();
// Action
$result = $easypaisa->sendRequest($requestData);
$this->assertInstanceOf(JsonResponse::class, $result);
}
public function testSendDirectRequestWithInvalidData()
{
// Data
$requestData = [
'orderId'=> '',
'transactionAmount' => -1,
'mobileAccountNo' => '',
'emailAddress' => 'abcgmail.com'
];
$easypaisa = new Easypaisa();
// Action
$result = $easypaisa->sendRequest($requestData);
$this->assertInstanceOf(JsonResponse::class, $result);
}
}

0 comments on commit 00f973e

Please sign in to comment.