src/BackOffice/ConfigurationBundle/Services/ApiPayment/Sogecommerce.php line 105

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: MAX
  5.  * Date: 08/04/14
  6.  * Time: 00:10
  7.  * FIXME: [NEVER USED]
  8.  * TODO: erase and restart on a clean slate
  9.  */
  10. namespace App\BackOffice\ConfigurationBundle\Services\ApiPayment;
  11. use App\BackOffice\ConfigurationBundle\Payment\Gateways\Sogecommerce\Message\Response;
  12. use App\BackOffice\ConfigurationBundle\Services\Crypt;
  13. use App\BackOffice\ConfigurationBundle\Services\Invoice\Invoices;
  14. use App\BackOffice\ConfigurationBundle\Services\Mailing\SendMail;
  15. use App\BackOffice\ConfigurationBundle\Services\Serializer;
  16. use DateTime;
  17. use JMS\Serializer\SerializerInterface;
  18. use Services\CampaignBundle\Manager\CampaignsManager;
  19. use Services\CampaignBundle\Manager\CampaignTypesManager;
  20. use Services\ConfigurationBundle\Entity\Roles;
  21. use Services\ConfigurationBundle\Manager\RolesManager;
  22. use Services\LocationBundle\Entity\UserAddress;
  23. use Services\LocationBundle\Manager\CountryManager;
  24. use Services\LocationBundle\Manager\UserAddressManager;
  25. use Services\PaymentBundle\Entity\Payment;
  26. use Services\PaymentBundle\Entity\Retry;
  27. use Services\PaymentBundle\Entity\UserTokens;
  28. use Services\PaymentBundle\Manager\PaymentManager;
  29. use Services\PaymentBundle\Manager\PaymentStatusManager;
  30. use Services\PaymentBundle\Manager\PaymentTestCardsManager;
  31. use Services\PaymentBundle\Manager\PaymentTestManager;
  32. use Services\PaymentBundle\Manager\PaymentTypesManager;
  33. use Services\PaymentBundle\Manager\UserTokensManager;
  34. use Services\UsersBundle\Entity\Unsubscribe;
  35. use Services\UsersBundle\Entity\UserInfos;
  36. use Services\UsersBundle\Entity\Users;
  37. use Services\UsersBundle\Manager\UnsubscribeManager;
  38. use Services\UsersBundle\Manager\UserInfosManager;
  39. use Services\UsersBundle\Manager\UsersManager;
  40. use Symfony\Component\DependencyInjection\ContainerInterface;
  41. class Sogecommerce
  42. {
  43.     protected $container;
  44.     protected $usersManager;
  45.     protected $rolesManager;
  46.     protected $userInfosManager;
  47.     protected $paymentManager;
  48.     protected $paymentStatusManager;
  49.     protected $campaignTypesManager;
  50.     protected $paymentTypesManager;
  51.     protected $sogecommerce;
  52.     protected $sendMail;
  53.     protected $crypt;
  54.     protected $campaignsManager;
  55.     protected $ip;
  56.     protected $site;
  57.     protected $serializerService;
  58.     protected $unsubscribeManager;
  59.     protected $token;
  60.     protected $_psp;
  61.     protected $userTokensManager;
  62.     protected $billingService;
  63.     protected $_brand;
  64.     private $serializer;
  65.     public function __construct(ContainerInterface $containerUsersManager $usersManagerRolesManager $rolesManagerUserInfosManager $userInfosManager
  66.         PaymentManager $paymentManagerPaymentStatusManager $paymentStatusManagerCampaignTypesManager $campaignTypesManagerPaymentTypesManager $paymentTypesManager
  67.         \App\BackOffice\ConfigurationBundle\Services\Sogecommerce\Sogecommerce $sogecommerceSendMail $sendMailCrypt $cryptCampaignsManager $campaignsManager
  68.         Serializer $serializerServiceUnsubscribeManager $unsubscribeManagerUserAddressManager $userAddressManagerCountryManager $countryManager
  69.         UserTokensManager $userTokensManagerBillingService $billingServiceSerializerInterface $serializer)
  70.     {
  71.         $this->container $container;
  72.         $this->usersManager $usersManager;
  73.         $this->rolesManager $rolesManager;
  74.         $this->userInfosManager $userInfosManager;
  75.         $this->paymentManager $paymentManager;
  76.         $this->paymentStatusManager $paymentStatusManager;
  77.         $this->campaignTypesManager $campaignTypesManager;
  78.         $this->paymentTypesManager $paymentTypesManager;
  79.         $this->sogecommerce $sogecommerce;
  80.         $this->sendMail $sendMail;
  81.         $this->crypt $crypt;
  82.         $this->campaignsManager $campaignsManager;
  83.         $this->serializerService $serializerService;
  84.         $this->unsubscribeManager $unsubscribeManager;
  85.         $this->countryManager $countryManager;
  86.         $this->userAddressManager $userAddressManager;
  87.         $this->userTokensManager $userTokensManager;
  88.         $this->billingService $billingService;
  89.         $this->serializer $serializer;
  90.     }
  91.     public function serializeEntity($entity)
  92.     {
  93.         return $this->serializer->serialize($entity'json');
  94.     }
  95.     public function generateAuthorization($site$cardPan$cardMonth$cardYear$cardCryptogram$cardHolder$user$psp$campaign$ip$token null$testEnv$brand null)
  96.     {
  97.         $response['code'] = 0;
  98.         $response['retry'] = 1;
  99.         $response['psp'] = $this->serializeEntity($psp);
  100.         $mdp substr(md5(time()), 08);
  101.         $this->_psp $psp;
  102.         $this->ip $ip;
  103.         $this->site $site;
  104.         $userCreate '';
  105.         $this->_brand $brand;
  106.         $orderId $site->getNameConfig().$user->id.'-T-'.time();
  107.         $createToken $this->sogecommerce->generateToken($cardPan$cardYear$cardMonth$cardCryptogram$orderId$user$psp$site);
  108.         if ($createToken['success']) {
  109.             $this->token $createToken['token'];
  110.         } else {
  111.             $price number_format($campaign->getCampaignType()->getFirstPrice() + $campaign->getCampaignInfo()->getPricePresentClient() + $campaign->getCampaignInfo()->getShippingCost(), 2'.''');
  112.             $response['paymentAttempt'] = $this->container->get('BillingService')->addPaymentAttemptOld($psp$campaign$user->mailfalse$createToken['error'], $price$site$brand$user->source$orderId);
  113.             return $response;
  114.         }
  115.         $description 'Inscription';
  116.         if ($campaign->getCampaignPaymentTypes()->getId() == 1) {
  117.             $attempt1 false;
  118.             $attempt2 false;
  119.             $price number_format($campaign->getCampaignInfo()->getPricePresentClient() + $campaign->getCampaignInfo()->getShippingCost(), 2'.''');
  120.             $priceBilling1 str_replace('.'''$price);
  121.             $orderId $site->getNameConfig().$user->id.'-'.time();
  122.             $result $this->sogecommerce->generateAuthorization($this->token$user$priceBilling1$orderId$psp$site);
  123.             if ($result['success']) {
  124.                 $attempt1 true;
  125.                 $response['paymentAttempt'] = $this->container->get('BillingService')->addPaymentAttemptOld($psp$campaign$user->mailtrue0000$price$site$brand$user->source$orderId);
  126.             } else {
  127.                 $response['paymentAttempt'] = $this->container->get('BillingService')->addPaymentAttemptOld($psp$campaign$user->mailfalse$result['error'], $price$site$brand$user->source$orderId);
  128.             }
  129.             $price number_format($campaign->getCampaignType()->getFirstPrice(), 2'.''');
  130.             $priceBilling2 str_replace('.'''$price);
  131.             $orderId2 $site->getNameConfig().$user->id.'-2-'.time();
  132.             $result2 $this->sogecommerce->generateAuthorization($this->token$user$priceBilling2$orderId2$psp$site);
  133.             if ($result2['success']) {
  134.                 $attempt2 true;
  135.                 $response['paymentAttempt2'] = $this->container->get('BillingService')->addPaymentAttemptOld($psp$campaign$user->mailtrue0000$price$site$brand$user->source$orderId2);
  136.             } else {
  137.                 $response['paymentAttempt2'] = $this->container->get('BillingService')->addPaymentAttemptOld($psp$campaign$user->mailfalse$result2['error'], $price$site$brand$user->source$orderId2);
  138.             }
  139.             if ($result['success'] and $result2['success']) {
  140.                 $result['ORDERID'] = $orderId;
  141.                 $result2['ORDERID'] = $orderId2;
  142.                 $returnCode $result['code'];
  143.                 $idTransaction $result['idTransaction'];
  144.                 $returnCode2 $result2['code'];
  145.                 $idTransaction2 $result2['idTransaction'];
  146.                 //if paiement immediat
  147.                 // FIXME: Arguments for this function call have changed so this call will fail
  148.                 $userCreate $this->billingService->createUser($user$campaign$mdp$cardPan$cardMonth$cardYear$cardCryptogram$this->_brand$ip$this->token$psp$site);
  149.                 if ($campaign->getCampaignPayment()->getId() == 1) {
  150.                     $result $this->sogecommerce->captureAuthorization($result['idTransaction'], $psp$site);
  151.                     $result['ORDERID'] = $orderId;
  152.                     $returnCode $result['code'];
  153.                     $idTransaction $result['idTransaction'];
  154.                 }
  155.                 $payments $this->billingService->create2payment($returnCode$returnCode2$idTransaction$idTransaction2$orderId$orderId2$this->token$userCreate$campaign$psp$site);
  156.                 $response['payments'] = $payments;
  157.                 $response['user'] = $this->serializeEntity($userCreate);
  158.                 $response['code'] = 1;
  159.             } else {
  160.                 $response['retry'] = $this->codeValid($response['code']);
  161.             }
  162.         }
  163.         if ($campaign->getCampaignPaymentTypes()->getId() == 2) {
  164.             $price number_format($campaign->getCampaignType()->getFirstPrice() + $campaign->getCampaignInfo()->getPricePresentClient() + $campaign->getCampaignInfo()->getShippingCost(), 2'.''');
  165.             $priceBilling1 str_replace('.'''$price);
  166.             $orderId $site->getNameConfig().$user->id.'-'.time();
  167.             $result $this->sogecommerce->generateAuthorization($this->token$user$priceBilling1$orderId$psp$site);
  168.             if ($result['success']) {
  169.                 $response['paymentAttempt'] = $this->container->get('BillingService')->addPaymentAttemptOld($psp$campaign$user->mailtrue0000$price$site$brand$user->source$orderId);
  170.                 $result['ORDERID'] = $orderId;
  171.                 $returnCode $result['code'];
  172.                 $idTransaction $result['idTransaction'];
  173.                 // FIXME: Arguments for this function call have changed so this call will fail
  174.                 $userCreate $this->billingService->createUser($user$campaign$mdp$cardPan$cardMonth$cardYear$cardCryptogram$this->_brand$ip$this->token$psp$site);
  175.                 if ($campaign->getCampaignPayment()->getId() == 1) {
  176.                     $result $this->sogecommerce->captureAuthorization($result['idTransaction'], $psp$site);
  177.                     $returnCode $result['code'];
  178.                     $idTransaction $result['idTransaction'];
  179.                 }
  180.                 $payments $this->billingService->createPayment($returnCode$idTransaction$orderId$this->token$userCreate$campaign$psp$site);
  181.                 $response['payments'] = $payments;
  182.                 $response['user'] = $this->serializeEntity($userCreate);
  183.                 $response['code'] = 1;
  184.             } else {
  185.                 $response['paymentAttempt'] = $this->container->get('BillingService')->addPaymentAttemptOld($psp$campaign$user->mailfalse$result['code'], $price$site$brand$user->source$orderId$idTransaction);
  186.                 $response['retry'] = $this->codeValid($response['code']);
  187.             }
  188.         }
  189.         if ($campaign->getCampaignPaymentTypes()->getId() == 3) {
  190.             $priceBilling1 number_format($campaign->getCampaignInfo()->getPricePresentClient() + $campaign->getCampaignInfo()->getShippingCost(), 2'.''');
  191.             $priceBilling1 str_replace('.'''$priceBilling1);
  192.             $orderId $site->getNameConfig().$user->id.'-'.time();
  193.             $result $this->sogecommerce->generateAuthorization($this->token$user$priceBilling1$orderId$psp$site);
  194.             if ($result['success']) {
  195.                 $response['paymentAttempt'] = $this->container->get('BillingService')->addPaymentAttemptOld($psp$campaign$user->mailtrue0000$price$site$brand$user->source$orderId);
  196.                 $result['ORDERID'] = $orderId;
  197.                 $returnCode $result['code'];
  198.                 $idTransaction $result['idTransaction'];
  199.                 // FIXME: Arguments for this function call have changed so this call will fail
  200.                 $userCreate $this->billingService->createUser($user$campaign$mdp$cardPan$cardMonth$cardYear$cardCryptogram$this->_brand$ip$this->token$psp$site);
  201.                 if ($campaign->getCampaignPayment()->getId() == 1) {
  202.                     $result $this->sogecommerce->captureAuthorization($result['idTransaction'], $psp$site);
  203.                     $result['ORDERID'] = $orderId;
  204.                     $returnCode $result['code'];
  205.                     $idTransaction $result['idTransaction'];
  206.                     $paymentStatus $this->paymentStatusManager->getPaymentStatusById(1);
  207.                 } else {
  208.                     $paymentStatus $this->paymentStatusManager->getPaymentStatusById(3);
  209.                 }
  210.                 $payments $this->billingService->createPaymentSpecial($returnCode$idTransaction$orderId$this->token$paymentStatus$userCreate$campaign$psp$site);
  211.                 $response['user'] = $this->serializeEntity($userCreate);
  212.                 $response['payments'] = $payments;
  213.                 $response['code'] = 1;
  214.             } else {
  215.                 $response['paymentAttempt'] = $this->container->get('BillingService')->addPaymentAttemptOld($psp$campaign$user->mailfalse$result['code'], $price$site$brand$user->source$orderId);
  216.                 $response['retry'] = $this->codeValid($response['code']);
  217.             }
  218.         }
  219.         $response['mdp'] = $mdp;
  220.         $response['user'] = $this->serializeEntity($userCreate);
  221.         $response['orderId'] = $orderId;
  222.         return $response;
  223.     }
  224.     public function paymentNewCard($site$cardPan$cardMonth$cardYear$cardCryptogram$user$psp$campaign$ip$token null$testEnv)
  225.     {
  226.         $mdp substr(md5(time()), 08);
  227.         $this->_psp $psp;
  228.         $this->ip $ip;
  229.         $this->site $site;
  230.         $userCreate '';
  231.         $this->token $token;
  232.         $payments '';
  233.         $priceBilling1 floatval($campaign->getCampaignType()->getPrice());
  234.         $result $this->hipayService->generateAuthorizationNewCard($token$site->getNameConfig().'reabo_'.time().'_'.$user->getId(), $priceBilling1'auto'$ip$user$psp$testEnv);
  235.         if ($result->state == 'completed') {
  236.             $result $this->hipayService->captureAuthorization($result->transactionReference$priceBilling1$psp);
  237.             $paymentStatus $this->paymentStatusManager->getPaymentStatusById(1);
  238.             $returnCode '';
  239.             $idTransaction '';
  240.             $payments $this->billingService->createPaymentNewCard($returnCode$idTransaction$token$paymentStatus$user$campaign$psp$site);
  241.         }
  242.         return $payments;
  243.     }
  244.     /**
  245.      * refund
  246.      */
  247.     public function refund($payment$amount)
  248.     {
  249.         $response['valide'] = 0;
  250.         $priceBilling1 number_format($amount2'.''');
  251.         $priceBilling1 str_replace('.'''$priceBilling1);
  252.         $refRefund $this->sogecommerce->refund($payment->getTransactionId(), $priceBilling1$payment->getPaymentTypes());
  253.         if ($refRefund['success'] == true) {
  254.             if ($refRefund['type'] != 'CAPTURED') {
  255.                 $amount $payment->getTransactionPrice();
  256.             }
  257.             $payment $this->billingService->proceedRefund($payment$amount);
  258.             $response['payment'] = $payment;
  259.             $response['valid'] = 1;
  260.         }
  261.         return $response;
  262.     }
  263.     public function codeValid($code)
  264.     {
  265.         // TODO: extend ApiPaymentBase and use parent validation for common errors
  266.         // if (parent::codeValid($code)) {
  267.         //     return true;
  268.         // }
  269.         if ($code '400' && $code '600') {
  270.             // accept all HTTP errors as temporary ones
  271.             return true;
  272.         }
  273.         $respone false;
  274.         $array = [
  275.             '4000001',
  276.             '4000002',
  277.             '4000003',
  278.             '4000004',
  279.             '4000006',
  280.             '4000007',
  281.             '4010101',
  282.             '4010103',
  283.             '4010307',
  284.         ];
  285.         if (in_array($code$array)) {
  286.             $respone true;
  287.         }
  288.         return $respone;
  289.     }
  290.     /**
  291.      * execute payment recurrence
  292.      * @param Payment $payment
  293.      */
  294.     public function executePayment($payment)
  295.     {
  296.         $user $payment->getUser();
  297.         $site $user->getSite();
  298.         if ($payment->getIsError()) {
  299.             return $this->executePaymentError($payment);
  300.         }
  301.         $transactionId '';
  302.         //verif cron task no too much speed and payment its always good for billing
  303.         $payment $this->paymentManager->getEntityById($payment->getId());
  304.         if ($payment->getPaymentStatus()->getId() != and $payment->getPaymentStatus()->getId() != 3) {
  305.             return false;
  306.         }
  307.         $transactionId '';
  308.         $this->site $site;
  309.         $data['site'] = $this->serializeEntity($site);
  310.         $data['valid'] = false;
  311.         $data['retry'] = false;
  312.         $data['delete'] = false;
  313.         $errorCode '';
  314.         //get payments were date < date now
  315.         //get User infos
  316.         $user $payment->getUser();
  317.         foreach ($user->getUserTokens() as $val) {
  318.             if ($val->getPaymentTypes() == $payment->getPaymentTypes() and $val->getIsActive() == true) {
  319.                 $wallet $val->getToken();
  320.                 $this->_brand $val->getBrand();
  321.                 break;
  322.             }
  323.         }
  324.         $price number_format($payment->getTransactionPrice(), 2'.''');
  325.         $priceBilling str_replace('.'''$price);
  326.         $error 0;
  327.         $verifP 0;
  328.         //Capture if is an autorisaton
  329.         if ($payment->getPaymentStatus()->getId() == 2) {
  330.             $orderId $payment->getOrderId();
  331.             $response $this->sogecommerce->captureAuthorization($payment->getTransactionId(), $payment->getPaymentTypes(), $this->site);
  332.             //crée tous les paramètres de la requete doAutho
  333.             if (!$response['success']) {
  334.                 $error 1;
  335.                 $errorCode $response['code'];
  336.             } else {
  337.                 $transactionId $response['idTransaction'];
  338.             }
  339.         }
  340.         //oneClickPayment if is not an autorisation
  341.         if ($payment->getPaymentStatus()->getId() == 3) {
  342.             $orderId $site->getNameConfig().$user->getId().'-'.time();
  343.             $response $this->sogecommerce->generatePayment(
  344.                 $wallet,
  345.                 $user,
  346.                 $priceBilling,
  347.                 $orderId,
  348.                 $payment->getPaymentTypes(),
  349.                 $site
  350.             );
  351.             if (!$response['success']) {
  352.                 $error 1;
  353.                 $errorCode $response['code'];
  354.             } else {
  355.                 $transactionId $response['idTransaction'];
  356.                 $payment->setOrderId($orderId);
  357.             }
  358.         }
  359.         if ($error == 0) {
  360.             //set role premium
  361.             $payment->getUser()->setRoles($this->rolesManager->getEntityById(6));
  362.             $payment->setNextPaymentDate(new \DateTime('now'));
  363.             $payment->setReturnCode(118);
  364.             //update payment
  365.             if ($verifP == 0) {
  366.                 $transactionId $response['idTransaction'];
  367.                 $payment->setTransactionId($response['idTransaction']);
  368.                 $payment->setOrderId($orderId);
  369.             }
  370.             $payment->setPaymentStatus($this->paymentStatusManager->getPaymentStatusById(1));
  371.             $this->paymentManager->flush();
  372.             $data['payment'] = $this->serializeEntity($payment);
  373.             $data['valid'] = true;
  374.             //create newpayment
  375.             $newPayment $this->billingService->saveNewPayment($payment);
  376.             $data['newPayment'] = $this->serializeEntity($newPayment);
  377.         } else {
  378.             if ($this->codeValid($errorCode)) {
  379.                 $dataRules2 $this->billingService->retryRules3($payment$price$errorCode$this->site);
  380.                 $payment->setTransactionId($transactionId);
  381.                 $payment->setReturnCode($errorCode);
  382.                 $payment->setNextPaymentDate(new \DateTime('now'));
  383.                 $this->paymentManager->flush();
  384.                 $data array_merge($data$dataRules2);
  385.             } else {
  386.                 $payment->setTransactionId($transactionId);
  387.                 $payment->setReturnCode($errorCode);
  388.                 $payment->setNextPaymentDate(new \DateTime('now'));
  389.                 $payment->getUser()->setRoles($this->rolesManager->getEntityById(Roles::ROLE_DELETE));
  390.                 $payment->setPaymentStatus($this->paymentStatusManager->getPaymentStatusById(8));
  391.                 $this->paymentManager->flush();
  392.                 $comment 'unsubscribe billing error';
  393.                 $this->unsubscribeManager->createIfNotExistsUnsubcribe($user, new DateTime('NOW'), $comment);
  394.                 $data['payment'] = $this->serializeEntity($payment);
  395.                 $data['valid'] = true;
  396.                 $data['delete'] = true;
  397.             }
  398.         }
  399.         $data['user'] = $this->serializeEntity($payment->getUser());
  400.         return $data;
  401.     }
  402.     /**
  403.      * execute payment error
  404.      * @param Payment $payment
  405.      */
  406.     protected function executePaymentError($payment)
  407.     {
  408.         $user $payment->getUser();
  409.         $site $user->getSite();
  410.         $this->site $site;
  411.         $data['site'] = $this->serializeEntity($site);
  412.         $data['valid'] = false;
  413.         $data['retry'] = false;
  414.         $data['delete'] = false;
  415.         $errorCode '';
  416.         //get payments were date < date now
  417.         foreach ($user->getUserTokens() as $val) {
  418.             if ($val->getPaymentTypes() == $payment->getPaymentTypes() and $val->getIsActive() == true) {
  419.                 $wallet $val->getToken();
  420.                 break;
  421.             }
  422.         }
  423.         $error 0;
  424.         $verifP 0;
  425.         $priceBilling str_replace('.'''$payment->getTransactionPrice());
  426.         $orderId $site->getNameConfig().$user->getId().'-'.time();
  427.         $response $this->sogecommerce->generatePayment($wallet$user$priceBilling$orderId$payment->getPaymentTypes(), $site);
  428.         $transactionId $response['idTransaction'];
  429.         if (!$response['success']) {
  430.             $error 1;
  431.             $errorCode $response['code'];
  432.         }
  433.         if ($error == 0) {
  434.             $payment->getUser()->setRoles($this->rolesManager->getEntityById(8));
  435.             if ($verifP == 0) {
  436.                 $payment->setTransactionId($transactionId);
  437.                 $payment->setOrderId($orderId);
  438.             }
  439.             $payment->setReturnCode(118);
  440.             $payment->setPaymentStatus($this->paymentStatusManager->getPaymentStatusById(1));
  441.             $payment->setTransactionPrice($priceBilling);
  442.             $payment->setNextPaymentDate(new \DateTime('NOW'));
  443.             $payment->setIsError(false);
  444.             $this->paymentManager->flush();
  445.             //create next payment
  446.             $newPayment $this->billingService->saveNewPayment($payment);
  447.             $payment->setNextPaymentDate(new \DateTime('NOW'));
  448.             $this->paymentManager->flush();
  449.             $data['payment'] = $this->serializeEntity($payment);
  450.             $data['newPayment'] = $this->serializeEntity($newPayment);
  451.             $data['valid'] = true;
  452.         } else {
  453.             if ($this->codeValid($errorCode)) {
  454.                 //update payment in error
  455.                 $payment->setTransactionId($transactionId);
  456.                 $payment->setReturnCode($errorCode);
  457.                 $payment->setNextPaymentDate(new \DateTime('now'));
  458.                 $payment->setPaymentStatus($this->paymentStatusManager->getPaymentStatusById(16));
  459.                 $payment->setOrderId('');
  460.                 $this->paymentManager->flush();
  461.                 //create new payment with isError = true
  462.                 $date = new \DateTime('NOW');
  463.                 $dataDate 'P3D';
  464.                 $date->add(new \DateInterval($dataDate));
  465.                 $newPayment = clone $payment;
  466.                 $newPayment->setNextPaymentDate($date);
  467.                 $newPayment->setIsError(true);
  468.                 $newPayment->setTransactionId('');
  469.                 $newPayment->setOrderId('');
  470.                 $newPayment->setReturnCode($errorCode);
  471.                 $newPayment->setPaymentStatus($this->paymentStatusManager->getPaymentStatusById(11));
  472.                 $newPayment->setRef($this->site->getNameConfig().time().'-'.$payment->getUser()->getId().'-er');
  473.                 $this->paymentManager->persistAndFlush($newPayment);
  474.                 $data['payment'] = $this->serializeEntity($payment);
  475.                 $data['newPayment'] = $this->serializeEntity($newPayment);
  476.             } else {
  477.                 //set role freemium
  478.                 $payment->setReturnCode($errorCode);
  479.                 $payment->setNextPaymentDate(new \DateTime('now'));
  480.                 $payment->getUser()->setRoles($this->rolesManager->getEntityById(Roles::ROLE_DELETE));
  481.                 //desabo
  482.                 $payment->setPaymentStatus($this->paymentStatusManager->getPaymentStatusById(8));
  483.                 $this->paymentManager->flush();
  484.                 $comment 'unsubscribe billing error';
  485.                 $this->unsubscribeManager->createIfNotExistsUnsubcribe($user, new \DateTime('NOW'), $comment);
  486.                 $data['payment'] = $this->serializeEntity($payment);
  487.                 $data['valid'] = true;
  488.                 $data['delete'] = true;
  489.             }
  490.         }
  491.         $data['user'] = $this->serializeEntity($payment->getUser());
  492.         return $data;
  493.     }
  494.     /**
  495.      * Get the Fatal Code List
  496.      * @return array
  497.      */
  498.     public function getFatalCodeList(): array
  499.     {
  500.         return Response::getFatalCodeList();
  501.     }
  502. }