Skip to content

Commit c85a664

Browse files
committed
Add PaymobMethodFeature to tests
1 parent dd50fb6 commit c85a664

File tree

3 files changed

+115
-2
lines changed

3 files changed

+115
-2
lines changed

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<directory suffix="Test.php">./tests/Unit</directory>
2424
</testsuite>
2525
<testsuite name="Feature">
26-
<directory suffix="Test.php">./tests/Feature</directory>
26+
<directory suffix="Feature.php">./tests/Feature</directory>
2727
</testsuite>
2828
</testsuites>
2929
<php>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
3+
namespace Shabayek\Payment\Tests\Feature\Paymob;
4+
5+
use Illuminate\Support\Str;
6+
use Illuminate\Support\Facades\Http;
7+
use Shabayek\Payment\Facade\Payment;
8+
use Shabayek\Payment\Tests\TestCase;
9+
use Illuminate\Support\Facades\Config;
10+
11+
/**
12+
* Class PaymobMethodFeature
13+
* @test
14+
*/
15+
class PaymobMethodFeature extends TestCase
16+
{
17+
/** @test*/
18+
public function test_payment_token_in_return_purchase_url_with_paymob()
19+
{
20+
$order_id = rand(1, 100);
21+
$payment_key = Str::random(512);
22+
Http::fake([
23+
// Stub a JSON response for paymob endpoints...
24+
'https://accept.paymobsolutions.com/api/auth/tokens' => Http::response(['token' => Str::random(512)], 200),
25+
'https://accept.paymobsolutions.com/api/ecommerce/orders' => Http::response(['id' => $order_id], 200),
26+
'https://accept.paymobsolutions.com/api/acceptance/payment_keys' => Http::response(['token' => $payment_key], 200),
27+
]);
28+
29+
$method_id = 2;
30+
$payment = Payment::store($method_id);
31+
32+
$payment->customer($this->customer());
33+
$payment->address($this->address());
34+
$payment->items($this->items());
35+
36+
$payUrl = $payment->purchase();
37+
$query = [];
38+
$parts = parse_url($payUrl, PHP_URL_QUERY);
39+
parse_str($parts, $query);
40+
41+
42+
$this->assertEquals($query['payment_token'], $payment_key);
43+
}
44+
/** @test*/
45+
public function test_iframe_in_return_purchase_url_with_paymob()
46+
{
47+
$iframe = rand(1000, 9999);
48+
Config::set('payment.stores.2.credentials.iframe_id', $iframe);
49+
$order_id = rand(1, 100);
50+
$payment_key = Str::random(512);
51+
Http::fake([
52+
// Stub a JSON response for paymob endpoints...
53+
'https://accept.paymobsolutions.com/api/auth/tokens' => Http::response(['token' => Str::random(512)], 200),
54+
'https://accept.paymobsolutions.com/api/ecommerce/orders' => Http::response(['id' => $order_id], 200),
55+
'https://accept.paymobsolutions.com/api/acceptance/payment_keys' => Http::response(['token' => $payment_key], 200),
56+
]);
57+
58+
$method_id = 2;
59+
$payment = Payment::store($method_id);
60+
61+
$payment->customer($this->customer());
62+
$payment->address($this->address());
63+
$payment->items($this->items());
64+
65+
$payUrl = $payment->purchase();
66+
67+
$parts = parse_url($payUrl, PHP_URL_PATH);
68+
$arr = explode('/', $parts);
69+
70+
$this->assertEquals($arr[4], $iframe);
71+
}
72+
73+
/**
74+
* Get customer fake data
75+
*
76+
* @return array
77+
*/
78+
private function customer(): array
79+
{
80+
return [
81+
'first_name' => 'John',
82+
'last_name' => 'Doe',
83+
'phone' => '+989120000000',
84+
'email' => '[email protected]',
85+
];
86+
}
87+
/**
88+
* Get items fake data
89+
*
90+
* @return array
91+
*/
92+
private function items(): array
93+
{
94+
return [
95+
"name" => "Product name",
96+
"description" => "Product description",
97+
"amount_cents" => 15000,
98+
"quantity" => 1
99+
];
100+
}
101+
102+
private function address(): array
103+
{
104+
return [
105+
'floor' => '1',
106+
'street' => 'Test street',
107+
'city' => 'Test city',
108+
'state' => 'Test state',
109+
'apartment' => 'Test apartment',
110+
'building' => 'Test building'
111+
];
112+
}
113+
}

tests/Unit/Paymob/PaymobRequestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function test_payment_keys_success()
129129
}
130130
/**
131131
* Get customer fake data
132-
*
132+
*
133133
* @return array
134134
*/
135135
private function customer(): array

0 commit comments

Comments
 (0)