<?php
/*
* Copyright (c) 2018 VeriTrans Inc., a Digital Garage company. All rights reserved.
* http://www.veritrans.co.jp/
*/
namespace Plugin\VeriTrans4G2\Controller;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\LockWaitTimeoutException;
use Plugin\VeriTrans4G2\Controller\AbstractVt4gController;
use Eccube\Service\CartService;
use Eccube\Service\OrderHelper;
use Eccube\Repository\OrderRepository;
use Eccube\Repository\Master\OrderStatusRepository;
use Plugin\VeriTrans4G2\Entity\Vt4gOrderPayment;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
* 決済関連コントローラー
*/
class PaymentController extends AbstractVt4gController
{
/**
* コンテナ
*/
protected $container;
/**
* エンティティーマネージャー
*/
protected $em;
/**
* VT用固定値配列
*/
protected $vt4gConst;
/**
* 汎用処理用ユーティリティ
*/
protected $util;
/**
* @var OrderRepository
*/
protected $orderRepository;
/**
* @var OrderStatusRepository
*/
protected $orderStatusRepository;
/**
* @var CartService
*/
protected $cartService;
/**
* コンストラクタ
* @param ContainerInterface $container
* @return void
*/
public function __construct(
ContainerInterface $container,
OrderRepository $orderRepository,
OrderStatusRepository $orderStatusRepository,
CartService $cartService
)
{
$this->container = $container;
$mdkService = $this->container->get('vt4g_plugin.service.vt4g_mdk');
$mdkService->checkMdk();
$this->em = $container->get('doctrine.orm.entity_manager');
$this->vt4gConst = $container->getParameter('vt4g_plugin.const');
$this->util = $container->get('vt4g_plugin.service.util');
$this->orderRepository = $orderRepository;
$this->orderStatusRepository = $orderStatusRepository;
$this->cartService = $cartService;
}
/**
* 購入フロー決済画面
*
* @Route("/shopping/vt4g_payment", name="vt4g_shopping_payment")
* @param Request $request リクエストデータ
* @return object ビューレスポンス|レダイレクトレスポンス
*/
public function index(Request $request, CartService $cartService, OrderRepository $orderRepository)
{
$mode = $request->get('mode');
$memo01 = null;
if (!empty($request->get('OrderId'))) {
$memo01 = $request->get('OrderId');
} elseif (!empty($request->get('orderId'))) {
$memo01 = $request->get('orderId');
}
if (!empty($memo01)) {
$orderPayment = $this->em->getRepository(Vt4gOrderPayment::class)->findOneBy(['memo01' => $memo01]);
//取引IDが登録されていない場合、エラー画面へ遷移
if (!$orderPayment instanceof Vt4gOrderPayment) {
return $this->container->get('vt4g_plugin.service.payment_base')->makeErrorResponse();
}
try {
list($order, $orderPayment) = $this->container->get('vt4g_plugin.service.payment_base')->getLockedOrder($orderPayment->getOrderId());
} catch (LockWaitTimeoutException $e) {
return $this->container->get('vt4g_plugin.service.payment_base')->makeErrorResponse(trans('vt4g_plugin.payment.shopping.lock_timeout'));
} catch (DriverException $e) {
return $this->container->get('vt4g_plugin.service.payment_base')->makeErrorResponse(trans('vt4g_plugin.payment.shopping.lock_timeout'));
}
$memo10 = unserialize($orderPayment->getMemo10());
if (!array_key_exists('orderCompleteFlg', $memo10) || $memo10['orderCompleteFlg']) {
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $order->getId()]);
}
} elseif (!empty($cartService->getPreOrderId())) {
$order = $orderRepository->findOneBy(['pre_order_id' => $cartService->getPreOrderId()]);
} else {
$order = null;
}
// 決済の入力チェック
$result = $this->container->get('vt4g_plugin.service.payment_base')->checkPaymentData($cartService, $order);
if ($result !== true) {
return $result;
}
$payment = $order->getPayment();
$payId = $this->util->getPayId($payment->getId());
$payCode = $this->util->getPayCode($payId);
$payload = [
'paymentType' => $payCode,
'mode' => $mode,
'order' => $order,
'paymentInfo' => $this->util->getPaymentMethodInfo($payment->getId()),
'user' => $this->getUser(),
'orderPayment' => $orderPayment ?? new Vt4gOrderPayment,
];
$method = "exec{$payCode}Process";
return $this->$method($request, $payload);
}
/**
* 購入フロー決済完了画面
*
* @Route("/shopping/vt4g_payment/complete", name="vt4g_shopping_payment_complete")
* @param Request $request リクエストデータ
* @return object リダイレクトレスポンス
*/
public function complete(Request $request)
{
$orderId = $request->get('no');
$order = $this->getOrderById($orderId);
// 注文が存在しない もしくは ログインユーザと注文者が一致しない場合
if (!$order || $this->getUser() != $order->getCustomer()) {
throw new NotFoundHttpException();
}
$orderPayment = $this->util->getOrderPayment($order->getId());
if (!$orderPayment instanceof Vt4gOrderPayment) {
return $this->container->get('vt4g_plugin.service.payment_base')->makeErrorResponse();
}
//ネットバンク決済を使用している時のみ、注文/決済ステータスを変更する。
$payId = $orderPayment->getMemo03();
if($payId == $this->vt4gConst['VT4G_PAYTYPEID_BANK']){
$bank = $this->container->get('vt4g_plugin.service.payment_bank');
$bank->changePayStatus($order, $orderPayment);
}
// 完了画面を表示するため、受注IDをセッションに保持する
$this->session->set(OrderHelper::SESSION_ORDER_ID, $order->getId());
return $this->redirectToRoute('shopping_complete');
}
/**
* 購入フロー決済 戻る処理
*
* @Route("/shopping/vt4g_payment/back", name="vt4g_shopping_payment_back")
* @param Request $request リクエストデータ
* @return object リダイレクトレスポンス
*/
public function back(Request $request)
{
$orderId = $request->get('no');
$order = $this->getOrderById($orderId);
// 注文が存在しない もしくは ログインユーザと注文者が一致しない場合
if (!$order || $this->getUser() != $order->getCustomer()) {
throw new NotFoundHttpException();
}
return $this->redirectToRoute('shopping');
}
/**
* クレジットカード決済処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execCreditProcess($request, $payload)
{
$credit = $this->container->get('vt4g_plugin.service.payment_credit');
$result = false;
$execPaymentFlg = false;
$error = [
'payment' => '',
'credit' => ''
];
// 入力フォーム送信時
if ($request->getMethod() === 'POST' && $payload['mode'] !== 'comp') {
$execPaymentFlg = true;
// POST用リクエストパラメータをsessionで指定した値に変更
if ($this->container->get('session')->has('vt4g_shopping_request')) {
$vt4gShoppingRequest = $this->container->get('session')->get('vt4g_shopping_request');
$this->container->get('session')->remove('vt4g_shopping_request');
$payload['mode'] = $vt4gShoppingRequest['mode'];
switch ($payload['mode']) {
case 'token': // MDKトークン利用
case 'retrade': // 再取引
case 'account': // ベリトランス会員ID決済
$this->execIsTokenValid($credit, $payload);
$result = $credit->commitNormalPayment($vt4gShoppingRequest, $payload, $error);
break;
default:
return $credit->makeErrorResponse();
}
} else {
$error['payment'] = trans('vt4g_plugin.payment.shopping.required.error');
$result = false;
};
}
if ($payload['mode'] === 'comp') {
$execPaymentFlg = true;
// 本人認証リダイレクト
$result = $credit->commitMpiPayment($request, $payload, $error);
}
if ($result) {
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}
// 入力フォーム上にエラー表示の場合はロールバックを行わない
if ($execPaymentFlg && empty($error['credit'])) {
// ロールバック
$credit->rollback($payload['order']);
}
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'orderNo' => $payload['order']->getId(),
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_10'],
'tplIsLoading' => (empty($error['payment']) && empty($error['credit'])),
'loadingImage' => $this->util->getLoadingImage()
]);
}
/**
* ATM決済処理
*
* @param request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execATMProcess($request, $payload)
{
$atm = $this->container->get('vt4g_plugin.service.payment_atm');
$error = [
'payment' => '',
];
if ('POST' === $request->getMethod() && $payload['mode'] == "next") {
$this->execIsTokenValid($atm, $payload);
$result = $atm->atmCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result){
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}
// ロールバック
$atm->rollback($payload['order']);
}
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_31'],
'orderNo' => $payload['order']->getId(),
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage()
]);
}
/**
* ネットバンク決済処理
*
* @param request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
public function execBankProcess($request, $payload)
{
$bank = $this->container->get('vt4g_plugin.service.payment_bank');
$error = [
'payment' => '',
];
// POST用リクエストパラメータ
$result = $bank->bankCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result == false){
// ロールバック
$bank->rollback($payload['order']);
}
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_30'],
'orderNo' => $payload['order']->getId(),
'paymentInfo' => $payload['paymentInfo'],
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage(),
'requestParam' => $result,
]);
}
/**
* コンビニ決済処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execCVSProcess($request, $payload)
{
$cvs = $this->container->get('vt4g_plugin.service.payment_cvs');
$error = [
'payment' => '',
];
// 入力フォーム送信時
if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
$this->execIsTokenValid($cvs, $payload);
// POST用リクエストパラメータをsessionで指定した値に変更
if ($this->container->get('session')->has('vt4g_shopping_request')) {
$vt4gCvsForm = $this->container->get('session')->get('vt4g_shopping_request');
$this->container->get('session')->remove('vt4g_shopping_request');
$request->request->set('payment_cvs',$vt4gCvsForm);
$result = $cvs->cvsCommit($payload['order'], $payload['orderPayment'], $request->request, $payload['paymentInfo'], $error);
} else {
$error['payment'] = trans('vt4g_plugin.payment.shopping.required.error');
$result = false;
}
if ($result !== false){
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
} else {
// ロールバック
$cvs->rollback($payload['order']);
}
}
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_20'],
'orderNo' => $payload['order']->getId(),
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage()
]);
}
/**
* Alipay決済処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execAlipayProcess($request, $payload)
{
$alipay = $this->container->get('vt4g_plugin.service.payment_alipay');
$error = [
'payment' => '',
];
$requestHtml ='';
if ($request->getMethod() === 'POST') {
if ($payload['mode'] == 'next') {
$this->execIsTokenValid($alipay, $payload);
// リダイレクト用HTML取得
$result = $alipay->alipayCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result !== false) {
$requestHtml = $result;
}else{
// ロールバック
$alipay->rollback($payload['order']);
}
} else {
// 戻り完了処理
$result = $alipay->alipayComplete($request, $payload['order'], $payload['orderPayment'], $error);
if ($payload['mode'] == 'success' && $result !== false) {
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}
// ロールバック
$alipay->rollback($payload['order']);
}
}
if ($requestHtml) {
return new Response(
$requestHtml,
Response::HTTP_OK,
[
'Cache-Control' => 'no-store, no-cache',
'Pragma' => 'no-cache',
'Expires' => '0',
'Content-Type' => 'text/html; charset=UTF-8'
]
);
} else {
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_50'],
'orderNo' => $payload['order']->getId(),
'paymentInfo' => $payload['paymentInfo'],
'loadingImage' => $this->util->getLoadingImage(),
'tplIsLoading' => empty($error['payment']),
]);
}
}
/**
* 銀聯ネット決済処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execUPOPProcess($request, $payload)
{
$upop = $this->container->get('vt4g_plugin.service.payment_upop');
$error = [
'payment' => '',
];
$requestHtml = '';
if ($request->getMethod() === 'POST') {
if ($payload['mode'] == "next") {
$this->execIsTokenValid($upop, $payload);
$result = $upop->upopCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result !== false) {
$requestHtml = $result;
} else {
$upop->rollback($payload['order']);
}
}
// 銀聯ネットから戻った場合
if ($payload['mode'] == "complete") {
$result = $upop->upopComplete($request, $payload['order'], $payload['orderPayment'], $error);
if ($result){
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}else{
$upop->rollback($payload['order']);
}
}
}
if ($requestHtml) {
return new Response(
$requestHtml,
Response::HTTP_OK,
[
'Cache-Control' => 'no-store, no-cache',
'Pragma' => 'no-cache',
'Expires' => '0',
'Content-Type' => 'text/html; charset=UTF-8'
]
);
} else {
// POST用リクエストパラメータ
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_40'],
'orderNo' => $payload['order']->getId(),
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage(),
]);
}
}
/**
* 楽天ペイ処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execRakutenProcess($request, $payload)
{
$rakuten = $this->container->get('vt4g_plugin.service.payment_rakuten');
$error = [
'payment' => '',
];
$requestHtml = '';
if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
$this->execIsTokenValid($rakuten, $payload);
$result = $rakuten->rakutenCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result !== false) {
$requestHtml = $result;
} else {
$rakuten->rollback($payload['order']);
}
}
if ($request->getMethod() === 'GET') {
// 楽天から成功で戻った場合
if ($payload['mode'] == "success") {
$result = $rakuten->rakutenComplete($request, $payload['order'], $payload['orderPayment'], $error);
if ($result){
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}else{
$rakuten->rollback($payload['order']);
}
// 楽天からエラーで戻った場合
}elseif ($payload['mode'] == "error") {
// エラー画面用のメッセージを設定してロールバック
$rakuten->getResponse($request, $payload['order'], $error);
$rakuten->rollback($payload['order']);
}
}
if ($requestHtml) {
return new Response(
$requestHtml,
Response::HTTP_OK,
[
'Cache-Control' => 'no-store, no-cache',
'Pragma' => 'no-cache',
'Expires' => '0',
'Content-Type' => 'text/html; charset=UTF-8'
]
);
} else {
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_60'],
'orderNo' => $payload['order']->getId(),
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage(),
]);
}
}
/**
* 楽天ペイV2処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execRakutenv2Process($request, $payload)
{
$rakutenV2 = $this->container->get('vt4g_plugin.service.payment_rakuten_v2');
$error = [
'payment' => '',
];
$requestHtml = '';
if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
$this->execIsTokenValid($rakutenV2, $payload);
$result = $rakutenV2->rakutenV2Commit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result !== false) {
$requestHtml = $result;
} else {
$rakutenV2->rollback($payload['order']);
}
}
if ($request->getMethod() === 'GET') {
// 楽天から成功で戻った場合
if ($payload['mode'] == "success") {
$result = $rakutenV2->rakutenV2Complete($request, $payload['order'], $payload['orderPayment'], $error);
if ($result){
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}else{
$rakutenV2->rollback($payload['order']);
}
// 楽天からエラーで戻った場合
}elseif ($payload['mode'] == "error") {
// エラー画面用のメッセージを設定してロールバック
$rakutenV2->getResponse($request, $payload['order'], $error);
$rakutenV2->rollback($payload['order']);
}
}
if ($requestHtml) {
return new Response(
$requestHtml,
Response::HTTP_OK,
[
'Cache-Control' => 'no-store, no-cache',
'Pragma' => 'no-cache',
'Expires' => '0',
'Content-Type' => 'text/html; charset=UTF-8'
]
);
} else {
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_63'],
'orderNo' => $payload['order']->getId(),
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage(),
]);
}
}
/**
* リクルートかんたん支払い処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execRecruitProcess($request, $payload)
{
$recruit = $this->container->get('vt4g_plugin.service.payment_recruit');
$error = [
'payment' => '',
];
if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
$this->execIsTokenValid($recruit, $payload);
$result = $recruit->recruitCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result !== false) {
// リクルートの画面にリダイレクト
return $this->redirect($result);
} else {
$recruit->rollback($payload['order']);
}
}
if ($request->getMethod() === 'GET') {
// リクルートから成功で戻った場合
if ($payload['mode'] == "success") {
$result = $recruit->recruitComplete($request, $payload['order'], $payload['orderPayment'], $error);
if ($result){
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}else{
$recruit->rollback($payload['order']);
}
// リクルートからエラーで戻った場合
}elseif ($payload['mode'] == "error") {
// エラー画面用のメッセージを設定してロールバック
$recruit->getResponse($request, $payload['order'], $error);
$recruit->rollback($payload['order']);
}
}
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_61'],
'orderNo' => $payload['order']->getId(),
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage(),
]);
}
/**
* LINE Pay処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execLINEPayProcess($request, $payload)
{
$line = $this->container->get('vt4g_plugin.service.payment_linepay');
$error = [
'payment' => '',
];
if ($request->getMethod() === 'POST' && $payload['mode'] == "next") {
$this->execIsTokenValid($line, $payload);
$result = $line->linepayCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result !== false) {
// LINEの画面にリダイレクト
return $this->redirect($result);
} else {
$line->rollback($payload['order']);
}
}
if ($request->getMethod() === 'GET') {
// LINEから成功で戻った場合
if ($payload['mode'] == "success") {
$result = $line->linepayComplete($request, $payload['order'], $payload['orderPayment'], $error);
if ($result){
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}else{
$line->rollback($payload['order']);
}
// LINEからエラーで戻った場合
} elseif ($payload['mode'] == "error") {
// エラー画面用のメッセージを設定してロールバック
$line->getResponse($request, $payload['order'], $error);
$line->rollback($payload['order']);
// LINEからキャンセルで戻った場合
} elseif ($payload['mode'] == "cancel") {
// レスポンスをログに出力、ロールバックしてご注文手続き画面へ
$line->getResponse($request, $payload['order'], $error);
$line->rollback($payload['order']);
return $this->redirectToRoute('vt4g_shopping_payment_back', ['no' => $payload['order']->getId()]);
}
}
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_62'],
'orderNo' => $payload['order']->getId(),
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage(),
]);
}
/**
* PayPal決済処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execPayPalProcess($request, $payload)
{
$paypal = $this->container->get('vt4g_plugin.service.payment_paypal');
$error = [
'payment' => '',
];
if ($request->getMethod() === 'POST' && $payload['mode'] == 'next') {
$this->execIsTokenValid($paypal, $payload);
$result = $paypal->PayPalCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result !== false) {
return $this->redirect($result);
} else {
// ロールバック
$paypal->rollback($payload['order']);
}
}
if ($request->getMethod() === 'GET') {
// paypalから成功で戻った場合
if($payload['mode'] == 'exec') {
$result = $paypal->PayPalComplete($request, $payload['order'], $payload['orderPayment'], $error);
if ($result !== false) {
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}else{
// ロールバック
$paypal->rollback($payload['order']);
}
// paypalからキャンセルで戻った場合
} elseif($payload['mode'] == 'back') {
$paypal->rollback($payload['order']);
return $this->redirectToRoute('vt4g_shopping_payment_back', ['no' => $payload['order']->getId()]);
}
}
// POST用リクエストパラメータ
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_70'],
'orderNo' => $payload['order']->getId(),
'paymentInfo' => $payload['paymentInfo'],
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage()
]);
}
/**
* PayPay処理
*
* @param Request $request リクエストデータ
* @param array $payload 決済処理に使用するデータ
* @return object リダイレクトレスポンス|ビューレスポンス
*/
private function execPayPayProcess($request, $payload)
{
$paypay = $this->container->get('vt4g_plugin.service.payment_paypay');
$error = [
'payment' => '',
];
$requestHtml = '';
if ($request->getMethod() === 'POST') {
if ($payload['mode'] == "next") {
$this->execIsTokenValid($paypay, $payload);
$result = $paypay->PayPayCommit($payload['order'], $payload['orderPayment'], $payload['paymentInfo'], $error);
if ($result !== false) {
$requestHtml = $result;
} else {
$paypay->rollback($payload['order']);
}
}
}
if ($request->getMethod() === 'GET'){
// PayPayから成功で戻った場合
if ($payload['mode'] == "success") {
$result = $paypay->PayPayComplete($request, $payload['order'], $payload['orderPayment'], $error);
if ($result){
return $this->redirectToRoute('vt4g_shopping_payment_complete', ['no' => $payload['order']->getId()]);
}else{
$paypay->rollback($payload['order']);
}
// PayPayからエラーで戻った場合
} elseif ($payload['mode'] == "error") {
// エラー画面用のメッセージを設定してロールバック
$paypay->getResponse($request, $payload['order'], $error);
$paypay->rollback($payload['order']);
// PayPayからキャンセルで戻った場合
} elseif ($payload['mode'] == "cancel") {
// レスポンスをログに出力、ロールバックしてご注文手続き画面へ
$paypay->getResponse($request, $payload['order'], $error);
$paypay->rollback($payload['order']);
return $this->redirectToRoute('vt4g_shopping_payment_back', ['no' => $payload['order']->getId()]);
}
}
if ($requestHtml) {
return new Response(
$requestHtml,
Response::HTTP_OK,
[
'Cache-Control' => 'no-store, no-cache',
'Pragma' => 'no-cache',
'Expires' => '0',
'Content-Type' => 'text/html; charset=Shift_JIS',
]
);
} else {
// POST用リクエストパラメータ
return $this->render('VeriTrans4G2/Resource/template/default/Shopping/vt4g_payment.twig', [
'paymentType' => $payload['paymentType'],
'error' => $error,
'title' => $this->vt4gConst['VT4G_PAYNAME_PAYTYPEID_80'],
'orderNo' => $payload['order']->getId(),
'tplIsLoading' => empty($error['payment']),
'loadingImage' => $this->util->getLoadingImage(),
]);
}
}
/**
* 注文IDから受注データを取得
*
* @param integer $orderId 注文ID
* @return \Eccube\Entity\Order Orderクラスインスタンス
*/
private function getOrderById($orderId)
{
return $this->orderRepository->findOneBy([
'id' => $orderId
]);
}
/**
* isTokenValidを実行し、例外が発生している場合はポイント等のロールバックを行う。
*
* @param object $paymentService 各支払のサービスクラス
* @param array $payload 決済処理に使用するデータ
*
* @throws AccessDeniedHttpException isTokenValidでトークンが有効ではないと判定された場合
*/
private function execIsTokenValid($paymentService, $payload)
{
try {
//CSRFチェック
$this->isTokenValid();
} catch (AccessDeniedHttpException $e) {
//ロールバックとエラー画面への遷移
$paymentService->rollback($payload['order']);
throw new AccessDeniedHttpException($e->getMessage());
}
}
}