|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByTIC\Omnipay\Twispay\Tests\Message; |
|
4
|
|
|
|
|
5
|
|
|
use ByTIC\Omnipay\Twispay\Message\PurchaseRequest; |
|
6
|
|
|
use ByTIC\Omnipay\Twispay\Message\PurchaseResponse; |
|
7
|
|
|
use ByTIC\Omnipay\Twispay\Tests\AbstractTest; |
|
8
|
|
|
use Guzzle\Http\Client as HttpClient; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request as HttpRequest; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class PurchaseRequestTest |
|
13
|
|
|
* @package ByTIC\Omnipay\Twispay\Tests\Message |
|
14
|
|
|
*/ |
|
15
|
|
|
class PurchaseRequestTest extends AbstractTest |
|
16
|
|
|
{ |
|
17
|
|
|
public function testSend() |
|
18
|
|
|
{ |
|
19
|
|
|
$class = $this->newPurchaseRequest(); |
|
20
|
|
|
$data = [ |
|
21
|
|
|
'siteId' => 11111, |
|
22
|
|
|
'apiKey' => 22222, |
|
23
|
|
|
'amount' => 123.0, |
|
24
|
|
|
'currency' => 123, |
|
25
|
|
|
'description' => 'lorem ipsum', |
|
26
|
|
|
'orderId' => 123, |
|
27
|
|
|
'notifyUrl' => 123, |
|
28
|
|
|
'returnUrl' => 123, |
|
29
|
|
|
'card' => 123, |
|
30
|
|
|
]; |
|
31
|
|
|
$class->initialize($data); |
|
32
|
|
|
$response = $class->send(); |
|
33
|
|
|
self::assertInstanceOf(PurchaseResponse::class, $response); |
|
34
|
|
|
foreach (['siteId', 'orderId', 'description'] as $key) { |
|
35
|
|
|
self::assertTrue($response->hasDataProperty($key), "Property [" . $key . "] not defined"); |
|
36
|
|
|
self::assertSame($data[$key], $response->getDataProperty($key)); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testSendIdentifierAutoSet() |
|
41
|
|
|
{ |
|
42
|
|
|
$class = $this->newPurchaseRequest(); |
|
43
|
|
|
$data = [ |
|
44
|
|
|
'siteId' => 11111, |
|
45
|
|
|
'apiKey' => 22222, |
|
46
|
|
|
'amount' => 123.0, |
|
47
|
|
|
'currency' => 123, |
|
48
|
|
|
'description' => 'lorem ipsum', |
|
49
|
|
|
'orderId' => 123, |
|
50
|
|
|
'notifyUrl' => 123, |
|
51
|
|
|
'returnUrl' => 123, |
|
52
|
|
|
'card' => 123, |
|
53
|
|
|
]; |
|
54
|
|
|
$class->initialize($data); |
|
55
|
|
|
$response = $class->send(); |
|
56
|
|
|
self::assertInstanceOf(PurchaseResponse::class, $response); |
|
57
|
|
|
self::assertStringStartsWith('anonymous', $response->getDataProperty('identifier')); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return PurchaseRequest |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function newPurchaseRequest() |
|
64
|
|
|
{ |
|
65
|
|
|
$client = new HttpClient(); |
|
66
|
|
|
$request = HttpRequest::createFromGlobals(); |
|
67
|
|
|
$request = new PurchaseRequest($client, $request); |
|
68
|
|
|
return $request; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|