|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tzsk\Payu\Tests\Feature; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase; |
|
6
|
|
|
use Illuminate\Support\Facades\Event; |
|
7
|
|
|
use Illuminate\Support\Facades\Session; |
|
8
|
|
|
use Illuminate\Support\Facades\URL; |
|
9
|
|
|
use Spatie\Snapshots\MatchesSnapshots; |
|
10
|
|
|
use Tzsk\Payu\Concerns\Attributes; |
|
11
|
|
|
use Tzsk\Payu\Concerns\Customer; |
|
12
|
|
|
use Tzsk\Payu\Concerns\Transaction; |
|
13
|
|
|
use Tzsk\Payu\Events\TransactionInitiated; |
|
14
|
|
|
use Tzsk\Payu\Facades\Payu; |
|
15
|
|
|
use Tzsk\Payu\Models\PayuTransaction; |
|
16
|
|
|
use Tzsk\Payu\Tests\Invoice; |
|
17
|
|
|
use Tzsk\Payu\Tests\TestCase; |
|
18
|
|
|
|
|
19
|
|
|
class InitiateTransactionTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
use RefreshDatabase, MatchesSnapshots; |
|
22
|
|
|
|
|
23
|
|
|
/** @test */ |
|
24
|
|
|
public function can_create_payu_response() |
|
25
|
|
|
{ |
|
26
|
|
|
Event::fake(); |
|
27
|
|
|
URL::shouldReceive('route') |
|
28
|
|
|
->andReturn('http://localhost/foo-status'); |
|
29
|
|
|
URL::shouldReceive('temporarySignedRoute') |
|
30
|
|
|
->andReturn(route('payu::redirect')); |
|
31
|
|
|
|
|
32
|
|
|
$payee = Customer::make() |
|
33
|
|
|
->firstName('John Doe') |
|
34
|
|
|
->email('[email protected]'); |
|
35
|
|
|
|
|
36
|
|
|
$params = Attributes::make() |
|
37
|
|
|
->udf1('client'); |
|
38
|
|
|
|
|
39
|
|
|
$payment = Transaction::make() |
|
40
|
|
|
->id('unique-transaction') |
|
41
|
|
|
->charge(100) |
|
42
|
|
|
->for('Product') |
|
43
|
|
|
->with($params) |
|
44
|
|
|
->to($payee); |
|
45
|
|
|
|
|
46
|
|
|
$response = Payu::initiate($payment)->via('biz') |
|
47
|
|
|
->redirect('http://localhost/transaction/status'); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertMatchesSnapshot($response->render()); |
|
50
|
|
|
|
|
51
|
|
|
/** @var PayuTransaction $transaction */ |
|
52
|
|
|
$transaction = PayuTransaction::query() |
|
53
|
|
|
->locate('unique-transaction'); |
|
54
|
|
|
$this->assertMatchesSnapshot($transaction->body->toArray()); |
|
55
|
|
|
$this->assertMatchesSnapshot($transaction->body->params->toArray()); |
|
56
|
|
|
$this->assertMatchesSnapshot($transaction->body->payee->toArray()); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertEquals('unique-transaction', Session::get('payuTransactionId')); |
|
59
|
|
|
Event::assertDispatched(TransactionInitiated::class, fn ($event) => $event->transaction instanceof PayuTransaction); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** @test */ |
|
63
|
|
|
public function can_create_payu_money_payments_response() |
|
64
|
|
|
{ |
|
65
|
|
|
Event::fake(); |
|
66
|
|
|
URL::shouldReceive('route') |
|
67
|
|
|
->andReturn('http://localhost/foo-status'); |
|
68
|
|
|
URL::shouldReceive('temporarySignedRoute') |
|
69
|
|
|
->andReturn(route('payu::redirect')); |
|
70
|
|
|
|
|
71
|
|
|
$payee = Customer::make() |
|
72
|
|
|
->firstName('John Doe Money') |
|
73
|
|
|
->email('[email protected]'); |
|
74
|
|
|
|
|
75
|
|
|
$params = Attributes::make() |
|
76
|
|
|
->udf1('money'); |
|
77
|
|
|
|
|
78
|
|
|
$payment = Transaction::make() |
|
79
|
|
|
->id('unique-money-transaction') |
|
80
|
|
|
->charge(100) |
|
81
|
|
|
->for('Product') |
|
82
|
|
|
->with($params) |
|
83
|
|
|
->to($payee); |
|
84
|
|
|
|
|
85
|
|
|
$response = Payu::initiate($payment) |
|
86
|
|
|
->via('money') |
|
87
|
|
|
->redirect('http://localhost/money/status'); |
|
88
|
|
|
|
|
89
|
|
|
$this->assertMatchesSnapshot($response->render()); |
|
90
|
|
|
|
|
91
|
|
|
/** @var PayuTransaction $transaction */ |
|
92
|
|
|
$transaction = PayuTransaction::query() |
|
93
|
|
|
->locate('unique-money-transaction'); |
|
94
|
|
|
$this->assertMatchesSnapshot($transaction->body->toArray()); |
|
95
|
|
|
$this->assertMatchesSnapshot($transaction->body->params->toArray()); |
|
96
|
|
|
$this->assertMatchesSnapshot($transaction->body->payee->toArray()); |
|
97
|
|
|
|
|
98
|
|
|
$this->assertEquals('unique-money-transaction', Session::get('payuTransactionId')); |
|
99
|
|
|
Event::assertDispatched(TransactionInitiated::class, fn ($event) => $event->transaction instanceof PayuTransaction); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** @test */ |
|
103
|
|
|
public function can_create_payu_morphed_payments_response() |
|
104
|
|
|
{ |
|
105
|
|
|
Event::fake(); |
|
106
|
|
|
URL::shouldReceive('route') |
|
107
|
|
|
->andReturn('http://localhost/morphed-status'); |
|
108
|
|
|
URL::shouldReceive('temporarySignedRoute') |
|
109
|
|
|
->andReturn(route('payu::redirect')); |
|
110
|
|
|
|
|
111
|
|
|
$payee = Customer::make() |
|
112
|
|
|
->firstName('John Doe Morphed') |
|
113
|
|
|
->email('[email protected]'); |
|
114
|
|
|
|
|
115
|
|
|
$params = Attributes::make() |
|
116
|
|
|
->udf1('morphed'); |
|
117
|
|
|
|
|
118
|
|
|
$payment = Transaction::make() |
|
119
|
|
|
->id('unique-morphed-transaction') |
|
120
|
|
|
->charge(100) |
|
121
|
|
|
->for('Product') |
|
122
|
|
|
->against(Invoice::fake()) |
|
123
|
|
|
->with($params) |
|
124
|
|
|
->to($payee); |
|
125
|
|
|
|
|
126
|
|
|
$response = Payu::initiate($payment)->via('biz') |
|
127
|
|
|
->redirect('http://localhost/money/status'); |
|
128
|
|
|
|
|
129
|
|
|
$this->assertMatchesSnapshot($response->render()); |
|
130
|
|
|
|
|
131
|
|
|
/** @var PayuTransaction $transaction */ |
|
132
|
|
|
$transaction = PayuTransaction::query() |
|
133
|
|
|
->locate('unique-morphed-transaction'); |
|
134
|
|
|
$this->assertMatchesSnapshot($transaction->body->toArray()); |
|
135
|
|
|
$this->assertMatchesSnapshot($transaction->body->params->toArray()); |
|
136
|
|
|
$this->assertMatchesSnapshot($transaction->body->payee->toArray()); |
|
137
|
|
|
$this->assertMatchesSnapshot($transaction->body->model->toArray()); |
|
138
|
|
|
$this->assertSame($transaction->toArray(), Invoice::fake()->transactions()->first()->toArray()); |
|
139
|
|
|
|
|
140
|
|
|
$this->assertEquals('unique-morphed-transaction', Session::get('payuTransactionId')); |
|
141
|
|
|
Event::assertDispatched(TransactionInitiated::class, fn ($event) => $event->transaction instanceof PayuTransaction); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|