Japanese English

PHP 難読化コードの復元・デコード

Wordpress 等でのPHPのマルウェア・ウィルス・改ざんコードをデコードして難読化をオンラインで解除し、
元の読みやすいコードに戻し解読できます。

※すべての難読化コードを解除できるわけではございませんのでご理解とご了承をお願いいたします。

下記のコードを難読化解除しました

<?php /* __________________________________________________ | Obfuscated by YAK Pro - Php Obfuscator 2.0.3 | | on 2023-10-31 14:25:57 | | GitHub: https://github.com/pk-fr/yakpro-po | |__________________________________________________| */ namespace Plugin\AmazonPayV2_42\Service;use Doctrine\ORM\E...



難読化されたPHPコード

<?php
/*   __________________________________________________
    |  Obfuscated by YAK Pro - Php Obfuscator  2.0.3   |
    |              on 2023-10-31 14:25:57              |
    |    GitHub: https://github.com/pk-fr/yakpro-po    |
    |__________________________________________________|
*/
namespace Plugin\AmazonPayV2_42\Service;use Doctrine\ORM\EntityManagerInterface;use Eccube\Common\EccubeConfig;use Eccube\Entity\Master\OrderStatus;use Eccube\Repository\BaseInfoRepository;use Eccube\Repository\CustomerRepository;use Eccube\Repository\Master\OrderStatusRepository;use Eccube\Service\CartService;use Eccube\Service\PurchaseFlow\PurchaseContext;use Eccube\Service\PurchaseFlow\PurchaseFlow;use Eccube\Service\PurchaseFlow\Processor\StockReduceProcessor;use Eccube\Service\PurchaseFlow\Processor\PointProcessor;use Plugin\AmazonPayV2_42\Entity\Master\AmazonStatus;use Plugin\AmazonPayV2_42\Exception\AmazonException;use Plugin\AmazonPayV2_42\Exception\AmazonPaymentException;use Plugin\AmazonPayV2_42\Repository\ConfigRepository;use Plugin\AmazonPayV2_42\Amazon\Pay\API\Client as AmazonPayClient;use Plugin\AmazonPayV2_42\Repository\Master\AmazonStatusRepository;use GuzzleHttp\Client;use Guzzle\Http\Exception\BadResponseException;use Guzzle\Http\Exception\CurlException;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\DependencyInjection\ContainerInterface;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Session\SessionInterface;use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;use Symfony\Component\Routing\Generator\UrlGeneratorInterface;use Carbon\Carbon;class AmazonRequestService extends AbstractController{protected $entityManager;protected $baseInfoRepository;protected $customerRepository;protected $cartService;protected $purchaseFlow;protected $eccubeConfig;protected $configRepository;protected $Config;protected $amazonApi;protected $amazonApiConfig;protected $session;protected $tokenStorage;protected $container;private $pointProcessor;private $stockReduceProcessor;private $amazonStatusRepository;private $orderStatusRepository;public function __construct(EntityManagerInterface $entityManager, BaseInfoRepository $baseInfoRepository, CustomerRepository $customerRepository, CartService $cartService, PurchaseFlow $cartPurchaseFlow, EccubeConfig $eccubeConfig, ConfigRepository $configRepository, SessionInterface $session, TokenStorageInterface $tokenStorage, OrderStatusRepository $orderStatusRepository, AmazonStatusRepository $amazonStatusRepository, StockReduceProcessor $stockReduceProcessor, PointProcessor $pointProcessor, ContainerInterface $container){goto N_c3y;bdZbb:$this->amazonApi = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];goto YP9R_;YP9R_:goto r1i74;goto pOaVB;PkGQG:$this->orderStatusRepository = $orderStatusRepository;goto pF50J;LvB88:$this->session = $session;goto Q5KGk;Y3knV:$this->pointProcessor = $pointProcessor;goto YXNDf;pF50J:$this->amazonStatusRepository = $amazonStatusRepository;goto dH_Ej;Q5KGk:$this->tokenStorage = $tokenStorage;goto PkGQG;qC0Pj:if ($this->Config->getAmazonAccountMode() == $this->eccubeConfig['amazon_pay_v2']['account_mode']['owned'] && $this->Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {goto ihTDO;}goto bdZbb;QCAPA:$this->cartService = $cartService;goto tcUM3;N_c3y:$this->entityManager = $entityManager;goto BenzV;ACZR4:$this->customerRepository = $customerRepository;goto QCAPA;tcUM3:$this->purchaseFlow = $cartPurchaseFlow;goto iYkew;nTv1h:$this->amazonApi = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];goto npflJ;YXNDf:$this->container = $container;goto Bho9g;pOaVB:ihTDO:goto nTv1h;iYkew:$this->eccubeConfig = $eccubeConfig;goto BbuH9;BenzV:$this->BaseInfo = $baseInfoRepository->get();goto ACZR4;dH_Ej:$this->stockReduceProcessor = $stockReduceProcessor;goto Y3knV;Bho9g:$this->Config = $this->configRepository->get();goto qC0Pj;glvDL:$this->amazonApiConfig = $this->eccubeConfig['amazon_pay_v2']['api']['config'];goto PMmBE;BbuH9:$this->configRepository = $configRepository;goto LvB88;npflJ:r1i74:goto glvDL;PMmBE:}private function payoutSellerOrderId($orderId, $request_type = ''){goto FiREA;FGoxK:$prefix = $prefix === '' ? '' : $prefix . '_';goto Uye1d;LcGKe:$arrInit = parse_ini_file($iniFile);goto D4zPa;AN23j:return $timestamp . $prefix . $request_attr . $orderId;goto n8QO0;BsDFU:Qw9qc:goto FGoxK;Uye1d:$timestamp = '';goto gY2fn;QU7uR:$timestamp = $timestamp === '' ? '' : $timestamp . '_';goto AN23j;gY2fn:if (!($this->Config->getAmazonAccountMode() === $this->eccubeConfig['amazon_pay_v2']['account_mode']['shared'])) {goto QFxN5;}goto pjy9W;pjy9W:$timestamp = Carbon::now()->timestamp;goto sZEUi;cZAVL:$iniFile = dirname(__FILE__) . '/../amazon_pay_config.ini';goto BqP0u;BqP0u:if (!file_exists($iniFile)) {goto Qw9qc;}goto LcGKe;D4zPa:$prefix = $arrInit['prefix'];goto BsDFU;sZEUi:QFxN5:goto QU7uR;cYygp:$prefix = '';goto cZAVL;FiREA:$request_attr = $request_type === '' ? '' : strtoupper($request_type) . '_';goto cYygp;n8QO0:}protected function getAmazonPayConfig(){goto MJ53i;ljbqd:return $config;goto OMfVL;AqBCv:$config = ['public_key_id' => $Config->getPublicKeyId(), 'private_key' => $this->eccubeConfig->get('kernel.project_dir') . '/' . $Config->getPrivateKeyPath(), 'sandbox' => $Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['sandbox'] ? true : false, 'region' => 'jp'];goto ljbqd;MJ53i:$Config = $this->configRepository->get();goto AqBCv;OMfVL:}public function createCheckoutSessionPayload($cart_key){goto rpb_8;x_zXw:return json_encode($payload, JSON_FORCE_OBJECT);goto S6Lgt;RGxIT:$payload = ['webCheckoutDetails' => ['checkoutReviewReturnUrl' => $router->generate('amazon_checkout_review', ['cart' => $cart_key], UrlGeneratorInterface::ABSOLUTE_URL)], 'paymentDetails' => ['allowOvercharge' => true], 'storeId' => $Config->getClientId(), 'deliverySpecifications' => ['addressRestrictions' => ['type' => 'Allowed', 'restrictions' => ['JP' => []]]]];goto x_zXw;DHehi:$router = $this->container->get('router');goto RGxIT;rpb_8:$Config = $this->configRepository->get();goto DHehi;S6Lgt:}public function createUpdateCheckoutSessionPayload($Order){goto uoYqy;lcJQg:if ($config->getSale() == $this->eccubeConfig['amazon_pay_v2']['sale']['authori']) {goto CWqcX;}goto VBzN0;aVoCA:Bsd_Q:goto tTJR_;H3RsD:if (!($Order->getPaymentTotal() == 0)) {goto LPnsh;}goto Ceuh7;Ceuh7:throw AmazonPaymentException::create(AmazonPaymentException::ZERO_PAYMENT);goto M0Cve;Ch2_z:return json_encode($payload, JSON_FORCE_OBJECT);goto mOcZ1;M0Cve:LPnsh:goto ke00k;f02kj:$payload['merchantMetadata']['merchantStoreName'] = $this->BaseInfo->getShopName();goto P88iE;fgz8V:goto kvfMg;goto aVoCA;P88iE:q7ybE:goto Ch2_z;n2EA1:kvfMg:goto b80B6;ke00k:$config = $this->configRepository->get();goto lcJQg;VBzN0:if ($config->getSale() == $this->eccubeConfig['amazon_pay_v2']['sale']['capture']) {goto Bsd_Q;}goto Sb3i1;T83jm:if (!(mb_strlen($this->BaseInfo->getShopName()) < 51)) {goto q7ybE;}goto f02kj;pfAVF:CWqcX:goto xMkoT;Sb3i1:goto kvfMg;goto pfAVF;b80B6:$payload = ['webCheckoutDetails' => ['checkoutResultReturnUrl' => $router->generate('amazon_pay_shopping_checkout_result', [], UrlGeneratorInterface::ABSOLUTE_URL)], 'paymentDetails' => ['paymentIntent' => $paymentIntent, 'canHandlePendingAuthorization' => false, 'chargeAmount' => ['amount' => (int) $Order->getPaymentTotal(), 'currencyCode' => "JPY"]], 'merchantMetadata' => ['merchantReferenceId' => $this->payoutSellerOrderId($Order->getId()), 'noteToBuyer' => ''], "platformId" => "A1LODGGQOBGE66"];goto T83jm;tTJR_:$paymentIntent = 'AuthorizeWithCapture';goto n2EA1;uoYqy:$router = $this->container->get('router');goto H3RsD;xMkoT:$paymentIntent = 'Authorize';goto fgz8V;mOcZ1:}public function createCompleteCheckoutSessionPayload($Order){$payload = ['chargeAmount' => ['amount' => (int) $Order->getPaymentTotal(), 'currencyCode' => 'JPY']];return json_encode($payload, JSON_FORCE_OBJECT);}public function createCaptureChargePayload($Order, $billingAmount = null){$payload = ['captureAmount' => ['amount' => is_null($billingAmount) ? (int) $Order->getPaymentTotal() : $billingAmount, 'currencyCode' => 'JPY']];return json_encode($payload, JSON_FORCE_OBJECT);}public function createCancelChargePayload($cancellationReason = null){$payload = ['cancellationReason' => $cancellationReason];return json_encode($payload, JSON_FORCE_OBJECT);}public function createCloseChargePermissionPayload($closureReason = null, $cancelPendingCharges = null){$payload = ['closureReason' => $closureReason, 'cancelPendingCharges' => $cancelPendingCharges];return json_encode($payload, JSON_FORCE_OBJECT);}public function createCreateRefundPayload($chargeId, $refundAmount){$payload = ['chargeId' => $chargeId, 'refundAmount' => ['amount' => $refundAmount, 'currencyCode' => $this->eccubeConfig['amazon_pay_v2']['api']['payload']['currency_code']]];return json_encode($payload, JSON_FORCE_OBJECT);}public function createCreateChargePayload($chargePermissionId, $paymentTotal, $CaptureNow = false, $canHandlePendingAuthorization = false){$payload = ['chargePermissionId' => $chargePermissionId, 'chargeAmount' => ['amount' => $paymentTotal, 'currencyCode' => $this->eccubeConfig['amazon_pay_v2']['api']['payload']['currency_code']], 'captureNow' => $CaptureNow, 'canHandlePendingAuthorization' => $canHandlePendingAuthorization];return json_encode($payload, JSON_FORCE_OBJECT);}public function updateCheckoutSession($Order, $amazonCheckoutSessionId){goto rFdef;I3cZe:return json_decode($result['response']);goto sxm8W;VWCiC:$result = $client->updateCheckoutSession($amazonCheckoutSessionId, $this->createUpdateCheckoutSessionPayload($Order));goto I3cZe;rFdef:$client = new AmazonPayClient($this->getAmazonPayConfig());goto VWCiC;sxm8W:}public function signaturePayload($payload){goto HCLtH;HCLtH:$client = new AmazonPayClient($this->getAmazonPayConfig());goto BNJfR;BNJfR:$signature = $client->generateButtonSignature($payload);goto ZbJVT;ZbJVT:return $signature;goto Ou5dz;Ou5dz:}public function getCheckoutSession($amazonCheckoutSessionId){goto FX8_9;ThApr:$result = $client->getCheckoutSession($amazonCheckoutSessionId);goto m5IUr;m5IUr:return json_decode($result['response']);goto KRFd2;FX8_9:$client = new AmazonPayClient($this->getAmazonPayConfig());goto ThApr;KRFd2:}public function completeCheckoutSession($Order, $amazonCheckoutSessionId){goto HKROQ;jXB5F:l73ki:goto haJq6;uPplq:logs('amazon_pay_v2')->info('▼completeCheckoutSession statusDetails = ' . var_export($checkoutSession->statusDetails, true));goto ylbRx;hpULF:return $response;goto keU73;kI6XW:if (!($checkoutSession && isset($checkoutSession->statusDetails->reasonCode))) {goto GrRjQ;}goto pGyaX;wey9m:if (!($response->reasonCode == 'CheckoutSessionCanceled')) {goto mJzu4;}goto Fpwt0;f34WV:logs('amazon_pay_v2')->info('▼completeCheckoutSession reasonCode = ' . $response->reasonCode . ', order_id = ' . $Order->getId());goto wey9m;keU73:EM8pe:goto r8Pqe;nK51X:MvFEt:goto f34WV;menEK:$response = json_decode($result['response']);goto ns02T;D0ZRo:b2xft:goto WQtHB;EvRkG:mJzu4:goto D0ZRo;QDqJV:if (isset($response->reasonCode)) {goto MvFEt;}goto mivu5;Fpwt0:$checkoutSession = $this->getCheckoutSession($amazonCheckoutSessionId);goto kI6XW;b_1hS:logs('amazon_pay_v2')->info('▼completeCheckoutSession 受注をキャンセルしました' . 'order_id = ' . $Order->getId());goto qfXFN;WQtHB:throw new AmazonException();goto tTmpZ;vIX8F:zjN63:goto WkfqR;HKROQ:$client = new AmazonPayClient($this->getAmazonPayConfig());goto bj1f5;TbInM:throw AmazonPaymentException::create($errorCode);goto vIX8F;WkfqR:GrRjQ:goto EvRkG;r8Pqe:goto b2xft;goto nK51X;qfXFN:if (!$errorCode) {goto zjN63;}goto TbInM;ylbRx:$this->cancelOrder($Order);goto b_1hS;QzT5y:if ($result['status'] == 200 || $result['status'] == 202) {goto l73ki;}goto QDqJV;bj1f5:$result = $client->completeCheckoutSession($amazonCheckoutSessionId, $this->createCompleteCheckoutSessionPayload($Order));goto menEK;ns02T:logs('amazon_pay_v2')->info('▼completeCheckoutSession http-status = ' . $result['status'] . ', order_id = ' . $Order->getId());goto QzT5y;mivu5:goto b2xft;goto jXB5F;pGyaX:$errorCode = AmazonPaymentException::getErrorCode($checkoutSession->statusDetails->reasonCode);goto uPplq;haJq6:if (!($response->statusDetails->state == 'Completed')) {goto EM8pe;}goto hpULF;tTmpZ:}private function cancelOrder($Order){goto PcZvT;PcZvT:$OrderStatus = $this->orderStatusRepository->find($this->orderStatusRepository->find(OrderStatus::CANCEL));goto c030x;pkxPV:$Order->setAmazonPayV2AmazonStatus($AmazonStatus);goto ARgG9;a6w4C:$AmazonStatus = $this->amazonStatusRepository->find(AmazonStatus::CANCEL);goto pkxPV;ARgG9:$this->entityManager->flush();goto xfDri;c030x:$Order->setOrderStatus($OrderStatus);goto a6w4C;xfDri:}public function captureCharge($chargeId, $Order, $billingAmount = null){goto Yue50;c521w:return json_decode($result['response']);goto h3L_V;NbYeH:$headers = ['x-amz-pay-Idempotency-Key' => uniqid()];goto HsVQg;HsVQg:$result = $client->captureCharge($chargeId, $this->createCaptureChargePayload($Order, $billingAmount), $headers);goto c521w;Yue50:$client = new AmazonPayClient($this->getAmazonPayConfig());goto NbYeH;h3L_V:}public function cancelCharge($chargeId, $cancellationReason = null){goto jmM41;jmM41:$payload = $this->createCancelChargePayload($cancellationReason);goto xu_XE;AIt8a:$result = $client->cancelCharge($chargeId, $payload);goto GGtxh;xu_XE:$client = new AmazonPayClient($this->getAmazonPayConfig());goto AIt8a;GGtxh:return json_decode($result['response']);goto PFFK3;PFFK3:}public function closeChargePermission($chargePermissionId, $closureReason = null, $cancelPendingCharges = true){goto AR4yf;O7s06:return json_decode($result['response']);goto J2jZN;XtRqA:$client = new AmazonPayClient($this->getAmazonPayConfig());goto E9e3U;E9e3U:$result = $client->closeChargePermission($chargePermissionId, $payload);goto O7s06;AR4yf:$payload = $this->createCloseChargePermissionPayload($closureReason, $cancelPendingCharges);goto XtRqA;J2jZN:}public function createRefund($chargeId, $refundAmount, $softDescriptor = null, $idempotencyKey = null){goto J3Z_D;nb_H8:PTIDB:goto izPFC;izPFC:if (!($idempotencyKey == null)) {goto VTnOG;}goto g2PEU;umBey:VTnOG:goto FMYjL;RR861:$client = new AmazonPayClient($this->getAmazonPayConfig());goto Ts0lm;tHgfz:if (!(null != $softDescriptor)) {goto PTIDB;}goto tD0f6;g2PEU:$idempotencyKey = uniqid();goto umBey;Ts0lm:$result = $client->createRefund($payload, $headers);goto MWwNn;J3Z_D:$payload = $this->createCreateRefundPayload($chargeId, $refundAmount);goto tHgfz;tD0f6:$payload = array_merge($payload, ["softDescriptor" => $softDescriptor]);goto nb_H8;FMYjL:$headers = ['x-amz-pay-Idempotency-Key' => $idempotencyKey];goto RR861;MWwNn:return json_decode($result['response']);goto yp6YD;yp6YD:}public function createCharge($chargePermissionId, $paymentTotal, $CaptureNow = false, $softDescriptor = null, $canHandlePendingAuthorization = false, $merchantMetadataMerchantReferenceId = null, $idempotencyKey = null){goto jNlFe;GQtMG:$payload = array_merge($payload, ["softDescriptor" => $softDescriptor]);goto miIYC;dudSD:VOlm3:goto XH1KN;tYwCE:if (!(null != $softDescriptor)) {goto kEkOS;}goto GQtMG;FV4Is:$idempotencyKey = uniqid();goto dudSD;wzFm5:if (!(null != $merchantMetadataMerchantReferenceId)) {goto sXA4X;}goto sFt67;sFt67:$payload = array_merge($payload, ["merchantMetadata" => ["merchantReferenceId" => $merchantMetadataMerchantReferenceId]]);goto LIYOW;jNlFe:$payload = $this->createCreateChargePayload($chargePermissionId, $paymentTotal, $CaptureNow, $canHandlePendingAuthorization);goto wzFm5;EIwGi:return json_decode($result['response']);goto i94GZ;Vu1gD:if (!($idempotencyKey == null)) {goto VOlm3;}goto FV4Is;XH1KN:$headers = ['x-amz-pay-Idempotency-Key' => $idempotencyKey];goto AKkKA;LIYOW:sXA4X:goto tYwCE;miIYC:kEkOS:goto Vu1gD;AKkKA:$client = new AmazonPayClient($this->getAmazonPayConfig());goto tbErg;tbErg:$result = $client->createCharge($payload, $headers);goto EIwGi;i94GZ:}public function getCharge($chargeId){goto j0lhv;rOaYd:return json_decode($result['response']);goto lM2PZ;j0lhv:$client = new AmazonPayClient($this->getAmazonPayConfig());goto gTXio;gTXio:$result = $client->getCharge($chargeId);goto rOaYd;lM2PZ:}public function createSigninPayload($returnUrl){goto oPNSD;vfjBE:return json_encode($payload, JSON_FORCE_OBJECT);goto CAS0f;oPNSD:$Config = $this->configRepository->get();goto r3udE;r3udE:$payload = ['signInReturnUrl' => $returnUrl, 'storeId' => $Config->getClientId()];goto vfjBE;CAS0f:}public function getBuyer($buyerToken, $headers = null){goto f1GJs;qmBuL:if (!($result['status'] != 200)) {goto OLlRg;}goto MxHDw;xwZTo:OLlRg:goto cn84W;MxHDw:throw new AmazonException();goto xwZTo;f1GJs:$client = new AmazonPayClient($this->getAmazonPayConfig());goto On38a;On38a:$result = $client->getBuyer($buyerToken, $headers);goto qmBuL;cn84W:return json_decode($result['response']);goto H1H1U;H1H1U:}public function loginWithBuyerId(Request $request, $buyerId){goto Ujm76;IbcWl:return false;goto mO6uP;Ujm76:$Customers = $this->customerRepository->getNonWithdrawingCustomers(['v2_amazon_user_id' => $buyerId]);goto lWuQi;mO6uP:Ekd0_:goto ANO0v;J8wht:$this->tokenStorage->setToken($token);goto wj6wQ;ANO0v:$token = new UsernamePasswordToken($Customers[0], null, 'customer', ['ROLE_USER']);goto J8wht;sOv0t:aAvR_:goto V_h4P;wj6wQ:$request->getSession()->migrate(true);goto yaQiv;yaQiv:$this->cartService->mergeFromPersistedCart();goto Q0mvb;V_h4P:$this->cartService->save();goto UZ0r4;lWuQi:if (!(empty($Customers[0]) || !$Customers[0] instanceof \Eccube\Entity\Customer)) {goto Ekd0_;}goto IbcWl;Q0mvb:foreach ($this->cartService->getCarts() as $Cart) {$this->purchaseFlow->validate($Cart, new PurchaseContext($Cart, $Customers[0]));eD5s2:}goto sOv0t;UZ0r4:return true;goto OwveE;OwveE:}}

デコード(難読化解除)されたコード

<?php

/*   __________________________________________________
    |  Obfuscated by YAK Pro - Php Obfuscator  2.0.3   |
    |              on 2023-10-31 14:25:57              |
    |    GitHub: https://github.com/pk-fr/yakpro-po    |
    |__________________________________________________|
*/
namespace Plugin\AmazonPayV2_42\Service;

use Doctrine\ORM\EntityManagerInterface;
use Eccube\Common\EccubeConfig;
use Eccube\Entity\Master\OrderStatus;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\CustomerRepository;
use Eccube\Repository\Master\OrderStatusRepository;
use Eccube\Service\CartService;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Eccube\Service\PurchaseFlow\Processor\StockReduceProcessor;
use Eccube\Service\PurchaseFlow\Processor\PointProcessor;
use Plugin\AmazonPayV2_42\Entity\Master\AmazonStatus;
use Plugin\AmazonPayV2_42\Exception\AmazonException;
use Plugin\AmazonPayV2_42\Exception\AmazonPaymentException;
use Plugin\AmazonPayV2_42\Repository\ConfigRepository;
use Plugin\AmazonPayV2_42\Amazon\Pay\API\Client as AmazonPayClient;
use Plugin\AmazonPayV2_42\Repository\Master\AmazonStatusRepository;
use GuzzleHttp\Client;
use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\Exception\CurlException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Carbon\Carbon;
class AmazonRequestService extends AbstractController
{
    protected $entityManager;
    protected $baseInfoRepository;
    protected $customerRepository;
    protected $cartService;
    protected $purchaseFlow;
    protected $eccubeConfig;
    protected $configRepository;
    protected $Config;
    protected $amazonApi;
    protected $amazonApiConfig;
    protected $session;
    protected $tokenStorage;
    protected $container;
    private $pointProcessor;
    private $stockReduceProcessor;
    private $amazonStatusRepository;
    private $orderStatusRepository;
    public function __construct(EntityManagerInterface $entityManager, BaseInfoRepository $baseInfoRepository, CustomerRepository $customerRepository, CartService $cartService, PurchaseFlow $cartPurchaseFlow, EccubeConfig $eccubeConfig, ConfigRepository $configRepository, SessionInterface $session, TokenStorageInterface $tokenStorage, OrderStatusRepository $orderStatusRepository, AmazonStatusRepository $amazonStatusRepository, StockReduceProcessor $stockReduceProcessor, PointProcessor $pointProcessor, ContainerInterface $container)
    {
        $this->entityManager = $entityManager;
        $this->BaseInfo = $baseInfoRepository->get();
        $this->customerRepository = $customerRepository;
        $this->cartService = $cartService;
        $this->purchaseFlow = $cartPurchaseFlow;
        $this->eccubeConfig = $eccubeConfig;
        $this->configRepository = $configRepository;
        $this->session = $session;
        $this->tokenStorage = $tokenStorage;
        $this->orderStatusRepository = $orderStatusRepository;
        $this->amazonStatusRepository = $amazonStatusRepository;
        $this->stockReduceProcessor = $stockReduceProcessor;
        $this->pointProcessor = $pointProcessor;
        $this->container = $container;
        $this->Config = $this->configRepository->get();
        if ($this->Config->getAmazonAccountMode() == $this->eccubeConfig['amazon_pay_v2']['account_mode']['owned'] && $this->Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['prod']) {
            $this->amazonApi = $this->eccubeConfig['amazon_pay_v2']['api']['prod'];
            goto npflJ;
        }
        $this->amazonApi = $this->eccubeConfig['amazon_pay_v2']['api']['sandbox'];
        npflJ:
        $this->amazonApiConfig = $this->eccubeConfig['amazon_pay_v2']['api']['config'];
    }
    private function payoutSellerOrderId($orderId, $request_type = '')
    {
        $request_attr = $request_type === '' ? '' : strtoupper($request_type) . '_';
        $prefix = '';
        $iniFile = "/var/www/html/../amazon_pay_config.ini";
        if (!file_exists($iniFile)) {
            goto Qw9qc;
        }
        $arrInit = parse_ini_file($iniFile);
        $prefix = $arrInit['prefix'];
        Qw9qc:
        $prefix = $prefix === '' ? '' : $prefix . '_';
        $timestamp = '';
        if (!($this->Config->getAmazonAccountMode() === $this->eccubeConfig['amazon_pay_v2']['account_mode']['shared'])) {
            goto QFxN5;
        }
        $timestamp = Carbon::now()->timestamp;
        QFxN5:
        $timestamp = $timestamp === '' ? '' : $timestamp . '_';
        return $timestamp . $prefix . $request_attr . $orderId;
    }
    protected function getAmazonPayConfig()
    {
        $Config = $this->configRepository->get();
        $config = ['public_key_id' => $Config->getPublicKeyId(), 'private_key' => $this->eccubeConfig->get('kernel.project_dir') . '/' . $Config->getPrivateKeyPath(), 'sandbox' => $Config->getEnv() == $this->eccubeConfig['amazon_pay_v2']['env']['sandbox'] ? true : false, 'region' => 'jp'];
        return $config;
    }
    public function createCheckoutSessionPayload($cart_key)
    {
        $Config = $this->configRepository->get();
        $router = $this->container->get('router');
        $payload = ['webCheckoutDetails' => ['checkoutReviewReturnUrl' => $router->generate('amazon_checkout_review', ['cart' => $cart_key], UrlGeneratorInterface::ABSOLUTE_URL)], 'paymentDetails' => ['allowOvercharge' => true], 'storeId' => $Config->getClientId(), 'deliverySpecifications' => ['addressRestrictions' => ['type' => 'Allowed', 'restrictions' => ['JP' => []]]]];
        return json_encode($payload, JSON_FORCE_OBJECT);
    }
    public function createUpdateCheckoutSessionPayload($Order)
    {
        $router = $this->container->get('router');
        if (!($Order->getPaymentTotal() == 0)) {
            $config = $this->configRepository->get();
            if ($config->getSale() == $this->eccubeConfig['amazon_pay_v2']['sale']['authori']) {
                $paymentIntent = 'Authorize';
                goto kvfMg;
            }
            if ($config->getSale() == $this->eccubeConfig['amazon_pay_v2']['sale']['capture']) {
                $paymentIntent = 'AuthorizeWithCapture';
                goto n2EA1;
            }
            n2EA1:
            kvfMg:
            $payload = ['webCheckoutDetails' => ['checkoutResultReturnUrl' => $router->generate('amazon_pay_shopping_checkout_result', [], UrlGeneratorInterface::ABSOLUTE_URL)], 'paymentDetails' => ['paymentIntent' => $paymentIntent, 'canHandlePendingAuthorization' => false, 'chargeAmount' => ['amount' => (int) $Order->getPaymentTotal(), 'currencyCode' => "JPY"]], 'merchantMetadata' => ['merchantReferenceId' => $this->payoutSellerOrderId($Order->getId()), 'noteToBuyer' => ''], "platformId" => "A1LODGGQOBGE66"];
            if (!(mb_strlen($this->BaseInfo->getShopName()) < 51)) {
                goto q7ybE;
            }
            $payload['merchantMetadata']['merchantStoreName'] = $this->BaseInfo->getShopName();
            q7ybE:
            return json_encode($payload, JSON_FORCE_OBJECT);
        }
        throw AmazonPaymentException::create(AmazonPaymentException::ZERO_PAYMENT);
    }
    public function createCompleteCheckoutSessionPayload($Order)
    {
        $payload = ['chargeAmount' => ['amount' => (int) $Order->getPaymentTotal(), 'currencyCode' => 'JPY']];
        return json_encode($payload, JSON_FORCE_OBJECT);
    }
    public function createCaptureChargePayload($Order, $billingAmount = null)
    {
        $payload = ['captureAmount' => ['amount' => is_null($billingAmount) ? (int) $Order->getPaymentTotal() : $billingAmount, 'currencyCode' => 'JPY']];
        return json_encode($payload, JSON_FORCE_OBJECT);
    }
    public function createCancelChargePayload($cancellationReason = null)
    {
        $payload = ['cancellationReason' => $cancellationReason];
        return json_encode($payload, JSON_FORCE_OBJECT);
    }
    public function createCloseChargePermissionPayload($closureReason = null, $cancelPendingCharges = null)
    {
        $payload = ['closureReason' => $closureReason, 'cancelPendingCharges' => $cancelPendingCharges];
        return json_encode($payload, JSON_FORCE_OBJECT);
    }
    public function createCreateRefundPayload($chargeId, $refundAmount)
    {
        $payload = ['chargeId' => $chargeId, 'refundAmount' => ['amount' => $refundAmount, 'currencyCode' => $this->eccubeConfig['amazon_pay_v2']['api']['payload']['currency_code']]];
        return json_encode($payload, JSON_FORCE_OBJECT);
    }
    public function createCreateChargePayload($chargePermissionId, $paymentTotal, $CaptureNow = false, $canHandlePendingAuthorization = false)
    {
        $payload = ['chargePermissionId' => $chargePermissionId, 'chargeAmount' => ['amount' => $paymentTotal, 'currencyCode' => $this->eccubeConfig['amazon_pay_v2']['api']['payload']['currency_code']], 'captureNow' => $CaptureNow, 'canHandlePendingAuthorization' => $canHandlePendingAuthorization];
        return json_encode($payload, JSON_FORCE_OBJECT);
    }
    public function updateCheckoutSession($Order, $amazonCheckoutSessionId)
    {
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $result = $client->updateCheckoutSession($amazonCheckoutSessionId, $this->createUpdateCheckoutSessionPayload($Order));
        return json_decode($result['response']);
    }
    public function signaturePayload($payload)
    {
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $signature = $client->generateButtonSignature($payload);
        return $signature;
    }
    public function getCheckoutSession($amazonCheckoutSessionId)
    {
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $result = $client->getCheckoutSession($amazonCheckoutSessionId);
        return json_decode($result['response']);
    }
    public function completeCheckoutSession($Order, $amazonCheckoutSessionId)
    {
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $result = $client->completeCheckoutSession($amazonCheckoutSessionId, $this->createCompleteCheckoutSessionPayload($Order));
        $response = json_decode($result['response']);
        logs('amazon_pay_v2')->info('▼completeCheckoutSession http-status = ' . $result['status'] . ', order_id = ' . $Order->getId());
        if ($result['status'] == 200 || $result['status'] == 202) {
            if (!($response->statusDetails->state == 'Completed')) {
                goto b2xft;
            }
            return $response;
        }
        if (isset($response->reasonCode)) {
            logs('amazon_pay_v2')->info('▼completeCheckoutSession reasonCode = ' . $response->reasonCode . ', order_id = ' . $Order->getId());
            if (!($response->reasonCode == 'CheckoutSessionCanceled')) {
                goto mJzu4;
            }
            $checkoutSession = $this->getCheckoutSession($amazonCheckoutSessionId);
            if (!($checkoutSession && isset($checkoutSession->statusDetails->reasonCode))) {
                goto GrRjQ;
            }
            $errorCode = AmazonPaymentException::getErrorCode($checkoutSession->statusDetails->reasonCode);
            logs('amazon_pay_v2')->info('▼completeCheckoutSession statusDetails = ' . var_export($checkoutSession->statusDetails, true));
            $this->cancelOrder($Order);
            logs('amazon_pay_v2')->info('▼completeCheckoutSession 受注をキャンセルしましたorder_id = ' . $Order->getId());
            if (!$errorCode) {
                GrRjQ:
                mJzu4:
                goto D0ZRo;
            }
            throw AmazonPaymentException::create($errorCode);
        }
        D0ZRo:
        b2xft:
        throw new AmazonException();
    }
    private function cancelOrder($Order)
    {
        $OrderStatus = $this->orderStatusRepository->find($this->orderStatusRepository->find(OrderStatus::CANCEL));
        $Order->setOrderStatus($OrderStatus);
        $AmazonStatus = $this->amazonStatusRepository->find(AmazonStatus::CANCEL);
        $Order->setAmazonPayV2AmazonStatus($AmazonStatus);
        $this->entityManager->flush();
    }
    public function captureCharge($chargeId, $Order, $billingAmount = null)
    {
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $headers = ['x-amz-pay-Idempotency-Key' => uniqid()];
        $result = $client->captureCharge($chargeId, $this->createCaptureChargePayload($Order, $billingAmount), $headers);
        return json_decode($result['response']);
    }
    public function cancelCharge($chargeId, $cancellationReason = null)
    {
        $payload = $this->createCancelChargePayload($cancellationReason);
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $result = $client->cancelCharge($chargeId, $payload);
        return json_decode($result['response']);
    }
    public function closeChargePermission($chargePermissionId, $closureReason = null, $cancelPendingCharges = true)
    {
        $payload = $this->createCloseChargePermissionPayload($closureReason, $cancelPendingCharges);
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $result = $client->closeChargePermission($chargePermissionId, $payload);
        return json_decode($result['response']);
    }
    public function createRefund($chargeId, $refundAmount, $softDescriptor = null, $idempotencyKey = null)
    {
        $payload = $this->createCreateRefundPayload($chargeId, $refundAmount);
        if (!(null != $softDescriptor)) {
            goto PTIDB;
        }
        $payload = array_merge($payload, ["softDescriptor" => $softDescriptor]);
        PTIDB:
        if (!($idempotencyKey == null)) {
            goto VTnOG;
        }
        $idempotencyKey = uniqid();
        VTnOG:
        $headers = ['x-amz-pay-Idempotency-Key' => $idempotencyKey];
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $result = $client->createRefund($payload, $headers);
        return json_decode($result['response']);
    }
    public function createCharge($chargePermissionId, $paymentTotal, $CaptureNow = false, $softDescriptor = null, $canHandlePendingAuthorization = false, $merchantMetadataMerchantReferenceId = null, $idempotencyKey = null)
    {
        $payload = $this->createCreateChargePayload($chargePermissionId, $paymentTotal, $CaptureNow, $canHandlePendingAuthorization);
        if (!(null != $merchantMetadataMerchantReferenceId)) {
            goto sXA4X;
        }
        $payload = array_merge($payload, ["merchantMetadata" => ["merchantReferenceId" => $merchantMetadataMerchantReferenceId]]);
        sXA4X:
        if (!(null != $softDescriptor)) {
            goto kEkOS;
        }
        $payload = array_merge($payload, ["softDescriptor" => $softDescriptor]);
        kEkOS:
        if (!($idempotencyKey == null)) {
            goto VOlm3;
        }
        $idempotencyKey = uniqid();
        VOlm3:
        $headers = ['x-amz-pay-Idempotency-Key' => $idempotencyKey];
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $result = $client->createCharge($payload, $headers);
        return json_decode($result['response']);
    }
    public function getCharge($chargeId)
    {
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $result = $client->getCharge($chargeId);
        return json_decode($result['response']);
    }
    public function createSigninPayload($returnUrl)
    {
        $Config = $this->configRepository->get();
        $payload = ['signInReturnUrl' => $returnUrl, 'storeId' => $Config->getClientId()];
        return json_encode($payload, JSON_FORCE_OBJECT);
    }
    public function getBuyer($buyerToken, $headers = null)
    {
        $client = new AmazonPayClient($this->getAmazonPayConfig());
        $result = $client->getBuyer($buyerToken, $headers);
        if (!($result['status'] != 200)) {
            return json_decode($result['response']);
        }
        throw new AmazonException();
    }
    public function loginWithBuyerId(Request $request, $buyerId)
    {
        $Customers = $this->customerRepository->getNonWithdrawingCustomers(['v2_amazon_user_id' => $buyerId]);
        if (!(empty($Customers[0]) || !$Customers[0] instanceof \Eccube\Entity\Customer)) {
            $token = new UsernamePasswordToken($Customers[0], null, 'customer', ['ROLE_USER']);
            $this->tokenStorage->setToken($token);
            $request->getSession()->migrate(true);
            $this->cartService->mergeFromPersistedCart();
            foreach ($this->cartService->getCarts() as $Cart) {
                $this->purchaseFlow->validate($Cart, new PurchaseContext($Cart, $Customers[0]));
            }
            $this->cartService->save();
            return true;
        }
        return false;
    }
}


■【無料】ワードプレス:マルウェアスキャン&セキュリティープラグイン [マルウェア・ウィルス検出と駆除]

■WordPress のマルウェア駆除、セキュリティー対策 カスタマイズや修正、引っ越し・復旧のご依頼承ります

(C)2019 ワードプレス ドクター All rights reserved.