forked from bitpay/bitpay-checkout-magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient.php
executable file
·46 lines (40 loc) · 1.43 KB
/
Client.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace Bitpay\BPCheckout\Model;
use BitPaySDK\Env;
use BitPaySDK\Tokens;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Framework\Serialize\Serializer\Json;
class Client
{
protected Config $config;
protected EncryptorInterface $encryptor;
protected Json $serializer;
public function __construct(
Config $config,
EncryptorInterface $encryptor,
Json $serializer
) {
$this->config = $config;
$this->encryptor = $encryptor;
$this->serializer = $serializer;
}
/**
* Initialize bitpay client
*
* @return \BitPaySDK\Client
* @throws \BitPaySDK\Exceptions\BitPayException
*/
public function initialize(): \BitPaySDK\Client
{
$env = $this->config->getBitpayEnv() === 'test' ? Env::TEST : Env::PROD;
$privateKeyPath = $this->config->getPrivateKeyPath();
$password = $this->encryptor->decrypt($this->config->getMerchantFacadePassword());
$tokenData = $this->encryptor->decrypt($this->config->getMerchantTokenData());
$serializedTokenData = $this->serializer->unserialize($tokenData);
$merchantToken = $serializedTokenData['data'][0]['token'];
$tokens = new Tokens($merchantToken);
$platformInfo = 'BitPay_Magento2_v10.1.0';
return \BitPaySDK\Client::createWithData($env, $privateKeyPath, $tokens, $password, null, $platformInfo);
}
}