1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tzsk\Payu\Tests\Feature; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Event; |
6
|
|
|
use Illuminate\Support\Facades\Http; |
7
|
|
|
use Tzsk\Payu\Events\TransactionFailed; |
8
|
|
|
use Tzsk\Payu\Events\TransactionSuccessful; |
9
|
|
|
use Tzsk\Payu\Gateway\Factory; |
10
|
|
|
use Tzsk\Payu\Models\PayuTransaction; |
11
|
|
|
use Tzsk\Payu\Tests\TestCase; |
12
|
|
|
|
13
|
|
|
class VerifyTransactionTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** @test */ |
16
|
|
|
public function can_verify_biz_transactions() |
17
|
|
|
{ |
18
|
|
|
Event::fake(); |
19
|
|
|
/** @var PayuTransaction $transaction */ |
20
|
|
|
$transaction = factory(PayuTransaction::class)->create(); |
21
|
|
|
|
22
|
|
|
$payload = [ |
23
|
|
|
'transaction_details' => [$transaction->transaction_id => ['status' => 'success']], |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
Http::fake([ |
27
|
|
|
'test.payu.in/*' => Http::response($payload), |
28
|
|
|
'*' => Http::response(''), |
29
|
|
|
]); |
30
|
|
|
|
31
|
|
|
$this->assertTrue($transaction->pending()); |
32
|
|
|
$this->assertFalse($transaction->successful()); |
33
|
|
|
|
34
|
|
|
$transaction->gateway->verifier()->handle($transaction); |
35
|
|
|
|
36
|
|
|
$fresh = $transaction->fresh(); |
37
|
|
|
$this->assertFalse($fresh->pending()); |
38
|
|
|
$this->assertTrue($fresh->successful()); |
39
|
|
|
Event::assertDispatched(TransactionSuccessful::class, fn ($event) => $event->transaction instanceof PayuTransaction); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** @test */ |
43
|
|
|
public function can_verify_not_found_biz_transactions() |
44
|
|
|
{ |
45
|
|
|
Event::fake(); |
46
|
|
|
/** @var PayuTransaction $transaction */ |
47
|
|
|
$transaction = factory(PayuTransaction::class)->create(); |
48
|
|
|
|
49
|
|
|
Http::fake([ |
50
|
|
|
'test.payu.in/*' => Http::response('', 404), |
51
|
|
|
'*' => Http::response(''), |
52
|
|
|
]); |
53
|
|
|
|
54
|
|
|
$this->assertTrue($transaction->pending()); |
55
|
|
|
$this->assertFalse($transaction->failed()); |
56
|
|
|
|
57
|
|
|
$transaction->gateway->verifier()->handle($transaction); |
58
|
|
|
|
59
|
|
|
$fresh = $transaction->fresh(); |
60
|
|
|
$this->assertFalse($fresh->pending()); |
61
|
|
|
$this->assertTrue($fresh->failed()); |
62
|
|
|
Event::assertDispatched(TransactionFailed::class, fn ($event) => $event->transaction instanceof PayuTransaction); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** @test */ |
66
|
|
|
public function can_verify_money_transactions() |
67
|
|
|
{ |
68
|
|
|
Event::fake(); |
69
|
|
|
/** @var PayuTransaction $transaction */ |
70
|
|
|
$transaction = factory(PayuTransaction::class)->create([ |
71
|
|
|
'gateway' => Factory::make('money'), |
72
|
|
|
]); |
73
|
|
|
|
74
|
|
|
$payload = ['result' => [['status' => 'success']]]; |
75
|
|
|
Http::fake([ |
76
|
|
|
'payumoney.com/*' => Http::response($payload), |
77
|
|
|
'*' => Http::response(''), |
78
|
|
|
]); |
79
|
|
|
|
80
|
|
|
$this->assertTrue($transaction->pending()); |
81
|
|
|
$this->assertFalse($transaction->successful()); |
82
|
|
|
|
83
|
|
|
$transaction->gateway->verifier()->handle($transaction); |
84
|
|
|
|
85
|
|
|
$fresh = $transaction->fresh(); |
86
|
|
|
$this->assertFalse($fresh->pending()); |
87
|
|
|
$this->assertTrue($fresh->successful()); |
88
|
|
|
Event::assertDispatched(TransactionSuccessful::class, fn ($event) => $event->transaction instanceof PayuTransaction); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** @test */ |
92
|
|
|
public function can_verify_not_found_money_transactions() |
93
|
|
|
{ |
94
|
|
|
Event::fake(); |
95
|
|
|
/** @var PayuTransaction $transaction */ |
96
|
|
|
$transaction = factory(PayuTransaction::class)->create([ |
97
|
|
|
'gateway' => Factory::make('money'), |
98
|
|
|
]); |
99
|
|
|
|
100
|
|
|
Http::fake([ |
101
|
|
|
'payumoney.com/*' => Http::response([], 404), |
102
|
|
|
'*' => Http::response(''), |
103
|
|
|
]); |
104
|
|
|
|
105
|
|
|
$this->assertTrue($transaction->pending()); |
106
|
|
|
$this->assertFalse($transaction->failed()); |
107
|
|
|
|
108
|
|
|
$transaction->gateway->verifier()->handle($transaction); |
109
|
|
|
|
110
|
|
|
$fresh = $transaction->fresh(); |
111
|
|
|
$this->assertFalse($fresh->pending()); |
112
|
|
|
$this->assertTrue($fresh->failed()); |
113
|
|
|
Event::assertDispatched(TransactionFailed::class, fn ($event) => $event->transaction instanceof PayuTransaction); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|