2
0

NewSupefinaSpeiLogic.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <?php
  2. namespace App\Http\logic\api;
  3. use App\dao\Estatisticas\RechargeWithDraw;
  4. use App\dao\Pay\PayController;
  5. use App\Http\helper\CreateOrder;
  6. use App\Http\helper\NumConfig;
  7. use App\Jobs\Order;
  8. use App\Models\PrivateMail;
  9. use App\Models\RecordUserDataStatistics;
  10. use App\Services\Aes;
  11. use App\Services\OrderServices;
  12. use App\Services\PayConfig;
  13. use App\Services\StoredProcedure;
  14. use App\Services\SupefinaSpei;
  15. use App\Services\CreateLog;
  16. use App\Util;
  17. use GuzzleHttp\Client;
  18. use Illuminate\Support\Facades\DB;
  19. use Illuminate\Support\Facades\Redis;
  20. /**
  21. * Supefina SPEI
  22. *
  23. */
  24. class NewSupefinaSpeiLogic extends BaseApiLogic
  25. {
  26. const AGENT = 108;
  27. public $result;
  28. public function pay_order($userId, $pay_amount, $userPhone, $userEmail, $userName, $GiftsID, $buyIP, $AdId, $eventType, $pay_method = '')
  29. {
  30. $PayVerify = new PayController();
  31. $pay_amount = $PayVerify->verify($userId, $GiftsID, $pay_amount);
  32. if ($PayVerify->verify($userId, $GiftsID, $pay_amount) === false) {
  33. $this->error = $PayVerify->getError();
  34. return false;
  35. }
  36. if ($pay_amount < 0) {
  37. $this->error = 'Payment error_4';
  38. return false;
  39. }
  40. $service = new SupefinaSpei('NewSupefinaSpei');
  41. $config = $service->config;
  42. $merId = $config['merId'] ?? '';
  43. $baseUrl = $config['baseUrl'] ?? '';
  44. $payinPath = $config['payinPath'] ?? '/api/supefina/transactions/collection';
  45. $callbackUrl = $config['callbackUrl'] ?? '';
  46. $countryId = $config['countryId'] ?? 'MX';
  47. $currency = $config['currency'] ?? 'MXN';
  48. $aesKey = $config['aesKey'] ?? '';
  49. $privateKey = $config['privateKey'] ?? '';
  50. $productNo = $config['productNo'] ?? '';
  51. if ($merId === '' || $baseUrl === '' || empty($privateKey) || $callbackUrl === '') {
  52. $this->error = 'Payment config error';
  53. return false;
  54. }
  55. $order_sn = CreateOrder::order_sn($userId);
  56. $logic = new OrderLogic();
  57. $amount = (int)round($pay_amount * NumConfig::NUM_VALUE);
  58. $logic->orderCreate($order_sn, $amount, 'NewSupefinaSpei', $userId, $pay_method, $GiftsID, $AdId, $eventType);
  59. $orderAmount = (string)(int)$pay_amount;
  60. if ($pay_amount != (int)$pay_amount) {
  61. $orderAmount = number_format($pay_amount, 2, '.', '');
  62. }
  63. $params = [
  64. 'merchantOrderNo' => $order_sn,
  65. 'amount' => $orderAmount,
  66. 'country' => $countryId,
  67. 'currency' => $currency,
  68. 'notifyUrl' => $callbackUrl,
  69. ];
  70. $headers = [
  71. 'version' => '1.0.0',
  72. 'merchantNo' => $merId,
  73. 'requestId' => mt_rand(100000, 999999) . time(),
  74. 'requestTime' => time() * 1000,
  75. ];
  76. $body = [
  77. 'productNo' => $productNo,
  78. 'data' => Aes::encrypt(json_encode($params), base64_decode($aesKey)),
  79. ];
  80. $sign = $this->sign($headers, $body, $privateKey);
  81. $headers['sign'] = $sign;
  82. $request_extra = \GuzzleHttp\json_encode(array_merge($headers, $params));
  83. CreateLog::pay_request($userPhone, $request_extra, $order_sn, $userEmail, $userId, $userName);
  84. $url = rtrim($baseUrl, '/') . $payinPath;
  85. Util::WriteLog('NewSupefinaSpei', 'payin request: ' . $url . ' | ' . $request_extra);
  86. try {
  87. $client = new Client();
  88. $result = $client->post($url, [
  89. 'headers' => $headers,
  90. 'json' => $body,
  91. ])->getBody()->getContents();
  92. } catch (\Throwable $e) {
  93. Util::WriteLog('NewSupefinaSpei_error', 'payin request exception: ' . $e->getMessage());
  94. $this->error = 'Payment processing error';
  95. return false;
  96. }
  97. Util::WriteLog('NewSupefinaSpei', 'payin response: ' . $result);
  98. try {
  99. $data = \GuzzleHttp\json_decode($result, true);
  100. } catch (\Throwable $e) {
  101. Util::WriteLog('NewSupefinaSpei_error', [$result, $e->getMessage()]);
  102. $this->error = 'Payment processing error';
  103. return false;
  104. }
  105. if (!isset($data['success']) || $data['success'] !== true) {
  106. $this->error = $data['message'] ?? 'Payment request failed';
  107. return false;
  108. }
  109. $decryptData = Aes::decrypt($data['data'], base64_decode($aesKey));
  110. Util::WriteLog('NewSupefinaSpei', 'payin response1: ' . $decryptData);
  111. $this->result = json_decode($decryptData, true);
  112. return $this->result;
  113. }
  114. /**
  115. * 代收回调:仅代收存在“实际金额与订单金额不一致”,以 realityAmount 入账
  116. *
  117. * @param array<string,mixed> $post
  118. */
  119. public function notify($post)
  120. {
  121. $order_sn = $post['merchantOrderNo'];
  122. if ($order_sn === '') {
  123. Util::WriteLog('NewSupefinaSpei_error', 'payin notify missing merchantOrderNo');
  124. return 'fail';
  125. }
  126. try {
  127. $order = DB::connection('write')->table('agent.dbo.order')
  128. ->lock('with(nolock)')
  129. ->where('order_sn', $order_sn)->first();
  130. if (!$order) {
  131. $order = DB::connection('write')->table('agent.dbo.order')
  132. ->lock('with(nolock)')
  133. ->where('payment_sn', $post['platformOrderNo'])
  134. ->first();
  135. if ($order) {
  136. Util::WriteLog('NewSupefinaSpei', 'repeat call by platformOrderNo: ' . $post['platformOrderNo']);
  137. return '{"success":true}';
  138. }
  139. $logic = new OrderLogic();
  140. $amount = 100;
  141. $logic->orderCreate($order_sn, $amount, 'NewSupefinaSpei', $order->user_id);
  142. $order = DB::connection('write')->table('agent.dbo.order')->where('order_sn', $order_sn)
  143. ->first();
  144. }
  145. if (!empty($order->pay_at) || !empty($order->finished_at)) {
  146. if ($order->payment_sn != $post['platformOrderNo']) {
  147. $logic = new OrderLogic();
  148. $amount = 100;
  149. $order_sn = $order_sn . '#' . time();
  150. $logic->orderCreate($order_sn, $amount, 'NewSupefinaSpei', $order->user_id);
  151. $order = DB::connection('write')->table('agent.dbo.order')->where('order_sn', $order_sn)
  152. ->first();
  153. } else {
  154. return '{"success":true}';
  155. }
  156. }
  157. $status = (string)($post['transStatus'] ?? '');
  158. if (in_array($status, ['FAILED', 'CLOSED', 'CANCELED'])) {
  159. $body = ['pay_status' => 2, 'updated_at' => date('Y-m-d H:i:s')];
  160. DB::connection('write')->table('agent.dbo.order')->where('order_sn', $order_sn)->update($body);
  161. return '{"success":true}';
  162. }
  163. if (in_array($status, ['REFUNDING', 'PARTIAL_REFUND', 'REFUNDED'])) {
  164. Util::WriteLog('NewSupefinaSpei', 'payin notify status refund: ' . $order_sn);
  165. return '{"success":true}';
  166. }
  167. if ($status !== 'SUCCESS') {
  168. Util::WriteLog('NewSupefinaSpei', 'payin notify status not success: ' . $order_sn);
  169. return '{"success":true}';
  170. }
  171. $GiftsID = $order->GiftsID ?: '';
  172. $userID = $order->user_id ?: '';
  173. $AdId = $order->AdId ?: '';
  174. $eventType = $order->eventType ?: '';
  175. $realityAmount = isset($post['amount']) ? (float)$post['amount'] : (float)($post['amount'] ?? 0);
  176. if ($realityAmount <= 0) {
  177. Util::WriteLog('NewSupefinaSpei_error', 'payin notify invalid realityAmount: ' . json_encode($post));
  178. return 'fail';
  179. }
  180. $payAmt = round($realityAmount, 2);
  181. $amountInScore = (int)round($payAmt * NumConfig::NUM_VALUE);
  182. $body = [
  183. 'payment_sn' => $post['platformOrderNo'] ?? '',
  184. 'pay_status' => 1,
  185. 'pay_at' => date('Y-m-d H:i:s'),
  186. 'finished_at' => date('Y-m-d H:i:s'),
  187. 'amount' => $amountInScore,
  188. 'updated_at' => date('Y-m-d H:i:s'),
  189. ];
  190. $body['payment_fee'] = $post['fee'] ?? 0;
  191. $service = new OrderServices();
  192. if ((int)$order->amount != $amountInScore) {
  193. $body['GiftsID'] = 0;
  194. $body['amount'] = $amountInScore;
  195. $Recharge = $payAmt;
  196. $give = 0;
  197. $favorable_price = $Recharge + $give;
  198. $czReason = 1;
  199. $cjReason = 45;
  200. } else {
  201. [$give, $favorable_price, $Recharge, $czReason, $cjReason] = $service->getPayInfo($GiftsID, $userID, $payAmt);
  202. }
  203. [$Score] = $service->addRecord($userID, $payAmt, $favorable_price, $order_sn, $GiftsID, $Recharge, $czReason, $give, $cjReason, $AdId, $eventType,
  204. $body['payment_fee'] ?? 0);
  205. Order::dispatch([$userID, $payAmt, $Score, $favorable_price, $GiftsID, $order_sn]);
  206. DB::connection('write')->table('agent.dbo.order')->where('order_sn', $order_sn)->update($body);
  207. Util::WriteLog('NewSupefinaSpei', 'payin success, order_sn=' . $order_sn . ', realityAmount=' . $realityAmount);
  208. return '{"success":true}';
  209. } catch (\Throwable $exception) {
  210. Util::WriteLog('NewSupefinaSpei_error', $exception->getMessage() . "\n" . $exception->getTraceAsString());
  211. throw $exception;
  212. }
  213. }
  214. public function payment($RecordID, $amount, $accountName, $phone, $email, $OrderId, $PixNum, $PixType, $IFSCNumber, $BranchBank, $BankNO)
  215. {
  216. // 查询提现订单
  217. $query = DB::connection('write')
  218. ->table('QPAccountsDB.dbo.OrderWithDraw')
  219. ->where('RecordID', $RecordID)
  220. ->first();
  221. if (!$query) {
  222. Util::WriteLog('NewSupefinaSpei', 'withdraw order not found: ' . $RecordID);
  223. return 'fail';
  224. }
  225. $config = (new PayConfig())->getConfig('NewSupefinaSpei');
  226. // 账户号:优先 PixNum,其次 BankNO
  227. $account = $PixNum ?: $BankNO;
  228. if (!$account) {
  229. Util::WriteLog('NewSupefinaSpei_error', 'missing account for withdraw: ' . $OrderId);
  230. return 'fail';
  231. }
  232. // 银行编号:优先 BankNO(如果看作 bankId),否则使用配置默认
  233. $bankId = $BranchBank;
  234. if ($bankId === '') {
  235. Util::WriteLog('NewSupefinaSpei_error', 'missing bankId for withdraw: ' . $OrderId);
  236. return 'fail';
  237. }
  238. // 提现金额是以分存储,转成两位小数金额
  239. $orderAmount = number_format($amount / 100, 2, '.', '');
  240. $bankList = config('games.mex_bank_list');
  241. try {
  242. $now = time() * 1000;
  243. $data = [
  244. 'transTime' => $now,
  245. 'merchantOrderNo' => $OrderId,
  246. 'amount' => (string)$orderAmount,
  247. 'country' => $config['country'] ?? 'MX',
  248. 'currency' => $config['currency'] ?? 'MXN',
  249. 'payeeInfo' => [
  250. 'accountInfo' => [
  251. 'accountNo' => $account,
  252. 'accountType' => mb_strlen($account) == 16 ? '20' : '10',
  253. ],
  254. 'bankInfo' => [
  255. 'bankCode' => $bankId,
  256. 'bankName' => $bankList[$bankId] ?? 'bank',
  257. ],
  258. 'payeeName' => $accountName ?: 'slot777',
  259. ],
  260. 'notifyUrl' => $config['cashCallbackUrl'],
  261. ];
  262. $url = $config['baseUrl'] . $config['transferPath'];
  263. $result = $this->sendRequest($url, 'TRANSFER', $data);
  264. if ($result === false) {
  265. return 'fail';
  266. }
  267. } catch (\Throwable $e) {
  268. Util::WriteLog('NewSupefinaSpei_error', 'payout request exception: ' . $e->getMessage());
  269. return '';
  270. }
  271. try {
  272. $responseData = \GuzzleHttp\json_decode($result, true);
  273. } catch (\Throwable $e) {
  274. Util::WriteLog('NewSupefinaSpei_error', [$result, $e->getMessage()]);
  275. $this->error = 'Payment processing error';
  276. return false;
  277. }
  278. if (!isset($responseData['success']) || $responseData['success'] !== true) {
  279. $this->error = $responseData['message'] ?? 'request failed';
  280. // 同步下单失败:如果订单在处理中(State=5),退回资金并标记失败
  281. if ((int)$query->State === 5) {
  282. $msg = $data['msg'] ?? 'NewSupefinaSpei payout failed';
  283. $WithDraw = $query->WithDraw + $query->ServiceFee;
  284. $bonus = '30000,' . $WithDraw;
  285. PrivateMail::failMail($query->UserID, $OrderId, $WithDraw, $msg, $bonus);
  286. $withdraw_data = [
  287. 'State' => 6,
  288. 'agent' => self::AGENT,
  289. 'finishDate' => now(),
  290. 'remark' => json_encode($data),
  291. ];
  292. DB::connection('write')
  293. ->table('QPAccountsDB.dbo.OrderWithDraw')
  294. ->where('OrderId', $query->OrderId)
  295. ->update($withdraw_data);
  296. $RecordData = ['after_state' => 6, 'update_at' => now()];
  297. DB::connection('write')
  298. ->table('QPAccountsDB.dbo.AccountsRecord')
  299. ->where('type', 1)
  300. ->where('RecordID', $RecordID)
  301. ->update($RecordData);
  302. }
  303. return 'fail';
  304. }
  305. $decryptData = Aes::decrypt($responseData['data'], base64_decode($config['aesKey']));
  306. Util::WriteLog('NewSupefinaSpei', 'transfer decrypt response: ' . $decryptData);
  307. $this->result = json_decode($decryptData, true);
  308. return $this->result;
  309. }
  310. public function cashNotify($post)
  311. {
  312. $OrderId = $post['merchantOrderNo'];
  313. if ($OrderId === '') {
  314. Util::WriteLog('NewSupefinaSpei_error', 'payout notify missing merchantOrderNo');
  315. return 'fail';
  316. }
  317. $query = DB::connection('write')
  318. ->table('QPAccountsDB.dbo.OrderWithDraw')
  319. ->where('OrderId', $OrderId)
  320. ->first();
  321. if (!$query) {
  322. Util::WriteLog('NewSupefinaSpei_error', 'withdraw order not found in notify: '.$OrderId);
  323. return '{"success":true}';
  324. }
  325. // 只处理 State=5 或 7 的订单,避免重复
  326. if (!in_array((int)$query->State, [5, 7], true)) {
  327. Util::WriteLog('NewSupefinaSpei', 'withdraw already handled: '.$OrderId);
  328. return '{"success":true}';
  329. }
  330. $status = $post['transStatus'] ?? '';
  331. $orderStatus = 0;
  332. if (in_array($status, ['SUCCESS'], true)) {
  333. $orderStatus = 1; // 成功
  334. } elseif (in_array($status, ['FAILED', 'CANCELED', 'REFUNDED'])) {
  335. $orderStatus = 2; // 失败
  336. }
  337. if ($orderStatus === 0) {
  338. Util::WriteLog('NewSupefinaSpei', 'payout processing: '.$OrderId.' status='.$status);
  339. return '{"success":true}';
  340. }
  341. $agentID = DB::connection('write')
  342. ->table('agent.dbo.admin_configs')
  343. ->where('config_value', self::AGENT)
  344. ->where('type', 'cash')
  345. ->value('id') ?? '';
  346. $now = now();
  347. $UserID = $query->UserID;
  348. $TakeMoney = $query->WithDraw + $query->ServiceFee;
  349. // Supefina 回调里带有 amount/fee 和 realityAmount/realityFee
  350. // 提醒:这里仍以我们订单金额为准做账,仅将真实金额用于日志,可根据需要扩展到统计侧。
  351. $realityAmount = isset($post['amount']) ? (float)$post['amount'] : null;
  352. $realityFee = isset($post['fee']) ? (float)$post['fee'] : null;
  353. Util::WriteLog('NewSupefinaSpei', 'payout reality: amount='.$realityAmount.', fee='.$realityFee.', orderId='.$OrderId);
  354. $withdraw_data = [];
  355. switch ($orderStatus) {
  356. case 1: // 提现成功
  357. $withdraw_data = [
  358. 'State' => 2,
  359. 'agent' => $agentID,
  360. 'finishDate' => $now,
  361. 'withdraw_fee' => $realityFee * NumConfig::NUM_VALUE,
  362. ];
  363. // 增加提现记录
  364. $first = DB::connection('write')
  365. ->table('QPAccountsDB.dbo.UserTabData')
  366. ->where('UserID', $UserID)
  367. ->first();
  368. if ($first) {
  369. DB::connection('write')
  370. ->table('QPAccountsDB.dbo.UserTabData')
  371. ->where('UserID', $UserID)
  372. ->increment('TakeMoney', $TakeMoney);
  373. } else {
  374. DB::connection('write')
  375. ->table('QPAccountsDB.dbo.UserTabData')
  376. ->insert(['TakeMoney' => $TakeMoney, 'UserID' => $UserID]);
  377. try {
  378. PrivateMail::praiseSendMail($UserID);
  379. } catch (\Throwable $e) {
  380. // 忽略邮件发送失败
  381. }
  382. }
  383. // 免审记录
  384. $withdrawal_position_log = DB::connection('write')
  385. ->table('agent.dbo.withdrawal_position_log')
  386. ->where('order_sn', $OrderId)
  387. ->first();
  388. if ($withdrawal_position_log) {
  389. DB::connection('write')
  390. ->table('agent.dbo.withdrawal_position_log')
  391. ->where('order_sn', $OrderId)
  392. ->update(['take_effect' => 2, 'update_at' => date('Y-m-d H:i:s')]);
  393. }
  394. try {
  395. StoredProcedure::addPlatformData($UserID, 4, $TakeMoney);
  396. } catch (\Throwable $exception) {
  397. Util::WriteLog('StoredProcedure', $exception->getMessage());
  398. }
  399. $ServiceFee = $query->ServiceFee;
  400. RecordUserDataStatistics::updateOrAdd($UserID, $TakeMoney, 0, $ServiceFee);
  401. $fee = DB::table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderId', $OrderId)
  402. ->value('withdraw_fee');
  403. (new RechargeWithDraw())->withDraw($UserID, $TakeMoney, $realityFee * NumConfig::NUM_VALUE, $ServiceFee);
  404. $redis = Redis::connection();
  405. $redis->incr('draw_'.date('Ymd').$UserID);
  406. break;
  407. case 2: // 提现失败
  408. $msg = $post['msg'] ?? 'Withdraw rejected';
  409. $bonus = '30000,'.$TakeMoney;
  410. PrivateMail::failMail($query->UserID, $OrderId, $TakeMoney, $msg, $bonus);
  411. Util::WriteLog('SupefinaSpeiEmail', [$query->UserID, $OrderId, $TakeMoney, $msg, $bonus]);
  412. $withdraw_data = [
  413. 'State' => 6,
  414. 'agent' => $agentID,
  415. 'remark' => $msg,
  416. ];
  417. break;
  418. }
  419. $RecordData = [
  420. 'before_state' => $query->State,
  421. 'after_state' => $withdraw_data['State'] ?? 0,
  422. 'RecordID' => $query->RecordID,
  423. 'update_at' => date('Y-m-d H:i:s'),
  424. ];
  425. DB::connection('write')
  426. ->table('QPAccountsDB.dbo.AccountsRecord')
  427. ->updateOrInsert(
  428. ['RecordID' => $query->RecordID, 'type' => 1],
  429. $RecordData
  430. );
  431. DB::connection('write')
  432. ->table('QPAccountsDB.dbo.OrderWithDraw')
  433. ->where('OrderId', $OrderId)
  434. ->update($withdraw_data);
  435. if (isset($withdraw_data['State']) && (int)$withdraw_data['State'] === 2) {
  436. StoredProcedure::user_label($UserID, 2, $TakeMoney);
  437. }
  438. return '{"success":true}';
  439. }
  440. public function getSignString($headers, $data)
  441. {
  442. $params = array_merge($headers, $data);
  443. $filtered = [];
  444. foreach ($params as $k => $v) {
  445. if (strtolower($k) === 'sign') {
  446. continue;
  447. }
  448. if ($v === null) {
  449. continue;
  450. }
  451. $filtered[$k] = $v;
  452. }
  453. ksort($filtered);
  454. $parts = [];
  455. foreach ($filtered as $k => $v) {
  456. $parts[] = $k . '=' . $v;
  457. }
  458. $signString = implode('&', $parts);
  459. return $signString;
  460. }
  461. public function sign($headers, $data, $key)
  462. {
  463. $signString = $this->getSignString($headers, $data);
  464. $res = openssl_pkey_get_private("-----BEGIN PRIVATE KEY-----\n" . $key . "\n-----END PRIVATE KEY-----");
  465. openssl_sign(
  466. $signString,
  467. $signature,
  468. $res,
  469. OPENSSL_ALGO_SHA256 // RSA2 核心
  470. );
  471. return base64_encode($signature);
  472. }
  473. public function verifySign($data, $sign, $key)
  474. {
  475. $res = openssl_pkey_get_public("-----BEGIN PUBLIC KEY-----\n" . $key . "\n-----END PUBLIC KEY-----");
  476. $result = openssl_verify(
  477. $data,
  478. base64_decode($sign),
  479. $res,
  480. OPENSSL_ALGO_SHA256
  481. );
  482. return $result === 1;
  483. }
  484. private function sendRequest($url, $productNo, $data)
  485. {
  486. $config = (new PayConfig())->getConfig('NewSupefinaSpei');
  487. $headers = [
  488. 'version' => '1.0.0',
  489. 'merchantNo' => $config['merId'] ?? '',
  490. 'requestId' => mt_rand(100000, 999999) . time(),
  491. 'requestTime' => time() * 1000,
  492. ];
  493. $body = [
  494. 'productNo' => $productNo,
  495. 'data' => Aes::encrypt(json_encode($data), base64_decode($config['aesKey'])),
  496. ];
  497. $sign = $this->sign($headers, $body, $config['privateKey']);
  498. $headers['sign'] = $sign;
  499. try {
  500. $client = new Client();
  501. Util::WriteLog('NewSupefinaSpei', $productNo . ' request: ' . $url . ' | ' . json_encode($data) . '|' . json_encode($headers));
  502. $result = $client->post($url, [
  503. 'headers' => $headers,
  504. 'json' => $body,
  505. ])->getBody()->getContents();
  506. Util::WriteLog('NewSupefinaSpei', $productNo . ' response: ' . $result);
  507. return $result;
  508. } catch (\Throwable $e) {
  509. Util::WriteLog('NewSupefinaSpei_error', $productNo . ' request exception: ' . $e->getMessage());
  510. $this->error = 'Payment processing error';
  511. return false;
  512. }
  513. }
  514. }