|
6 | 6 |
|
7 | 7 | class BackendPurchaseRequest extends AbstractRequest |
8 | 8 | { |
| 9 | + protected $liveEndpoint = 'https://gw.every-pay.eu'; |
| 10 | + protected $testEndpoint = 'https://gw-demo.every-pay.com'; |
| 11 | + |
9 | 12 | public function getData() |
10 | 13 | { |
11 | 14 | $data = $this->getBaseData(); |
@@ -35,24 +38,42 @@ public function setEmail($value) |
35 | 38 | return $this->setParameter('email', $value); |
36 | 39 | } |
37 | 40 |
|
38 | | - public function sendData($data) |
| 41 | + protected function signData($envelope, $data) |
39 | 42 | { |
40 | | - // TODO: Production |
41 | | - // $endpoint = 'https://gw.every-pay.eu/'; |
42 | | - $endpoint = 'https://gw-demo.every-pay.com/'; |
43 | | - |
44 | | - $payload = [ |
45 | | - 'charge' => SignedData::make( |
| 43 | + return [ |
| 44 | + $envelope => SignedData::make( |
46 | 45 | $data, |
47 | 46 | SignedDataOptions::backend($this->getSecret()) |
48 | 47 | ) |
49 | 48 | ]; |
| 49 | + } |
50 | 50 |
|
51 | | - $response = $this->httpClient->request('POST', sprintf('%s%s', $endpoint, 'charges'), [ |
| 51 | + protected function createResponse($response) |
| 52 | + { |
| 53 | + $status = $response->getStatusCode(); |
| 54 | + $body = $response->getBody()->getContents(); |
| 55 | + $body = @json_decode($body, true); |
| 56 | + |
| 57 | + $data = compact('status', 'body'); |
| 58 | + return $this->response = new BackendPurchaseResponse($this, $data); |
| 59 | + } |
| 60 | + |
| 61 | + public function sendData($data) |
| 62 | + { |
| 63 | + $headers = [ |
52 | 64 | 'Accept' => 'application/json', |
53 | 65 | 'Content-Type' => 'application/json', |
54 | | - ], json_encode($payload)); |
| 66 | + ]; |
| 67 | + |
| 68 | + $data = $this->signData('charge', $data); |
| 69 | + |
| 70 | + $response = $this->httpClient->request( |
| 71 | + 'POST', |
| 72 | + $this->getEndpoint() . '/charges', |
| 73 | + $headers, |
| 74 | + json_encode($data) |
| 75 | + ); |
55 | 76 |
|
56 | | - return $this->response = new BackendPurchaseResponse($this, $response->getBody()->getContents()); |
| 77 | + return $this->createResponse($response); |
57 | 78 | } |
58 | 79 | } |
0 commit comments