1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Service\Braintree; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class ForwardApiService |
9
|
|
|
* @package App\Service\Braintree |
10
|
|
|
*/ |
11
|
|
|
class ForwardApiService extends AbstractBraintreeService |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var string |
15
|
|
|
*/ |
16
|
|
|
public string $DIRECT_TOKEN_ENDPOINT = "https://forwarding.sandbox.braintreegateway.com/tsp"; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param string $paymentNonce |
20
|
|
|
* @param string $deviceData |
21
|
|
|
* @return array|null |
22
|
|
|
*/ |
23
|
|
|
public function directTokenization(string $paymentNonce, string $deviceData): ?array |
24
|
|
|
{ |
25
|
|
|
try { |
26
|
|
|
$ch = curl_init(); |
27
|
|
|
curl_setopt($ch, CURLOPT_URL, $this->DIRECT_TOKEN_ENDPOINT); |
28
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type:application/json']); |
29
|
|
|
curl_setopt( |
30
|
|
|
$ch, |
31
|
|
|
CURLOPT_USERPWD, |
32
|
|
|
$this->gateway->config->getPublicKey() . ':' . $this->gateway->config->getPrivateKey() |
33
|
|
|
); |
34
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); |
35
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ |
36
|
|
|
'merchant_id' => $this->gateway->config->getMerchantId(), |
37
|
|
|
'payment_method_nonce' => $paymentNonce, |
38
|
|
|
'device_data' => $deviceData, |
39
|
|
|
], true)); |
|
|
|
|
40
|
|
|
|
41
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
42
|
|
|
$result = curl_exec($ch); |
43
|
|
|
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
44
|
|
|
curl_close($ch); |
45
|
|
|
} catch (Exception $e) { |
46
|
|
|
$this->logger->error('Error on ForwardAPI::'.$this->DIRECT_TOKEN_ENDPOINT.' = ' . $e->getMessage()); |
47
|
|
|
return null; |
48
|
|
|
} |
49
|
|
|
return ([ |
50
|
|
|
'result' => (object) json_decode($result), |
|
|
|
|
51
|
|
|
'statusCode' => $statusCode |
52
|
|
|
]); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|