Skip to content

Commit

Permalink
Merge pull request #20 from BFoucher/retun-order-on-success-v2
Browse files Browse the repository at this point in the history
return orderId on success response
  • Loading branch information
paulandrieux authored Sep 20, 2016
2 parents f46b25f + ec907d0 commit 25ef9a0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
36 changes: 19 additions & 17 deletions Controller/PaymentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function newAction(Request $request, $order)

return $this->render(
'AppVentusMangopayBundle::cardPayment.html.twig',
array(
'form' => $form->createView(),
[
'form' => $form->createView(),
'order' => $order,
)
]
);
}

Expand Down Expand Up @@ -87,13 +87,13 @@ public function paymentFinalizeAction(Request $request, $orderId, $cardId)
// Handle error
if ((property_exists($updatedCardRegister, 'ResultCode')
&& $updatedCardRegister->ResultCode !== '000000')
|| $updatedCardRegister->Status == 'ERROR') {
|| $updatedCardRegister->Status == 'ERROR') {
$errorMessage = $this->get('translator')->trans('mangopay.error.'.$updatedCardRegister->ResultCode);

return new JsonResponse(array(
return new JsonResponse([
'success' => false,
'message' => $errorMessage,
));
]);
}

// Create a PayIn
Expand All @@ -103,17 +103,17 @@ public function paymentFinalizeAction(Request $request, $orderId, $cardId)
if ((property_exists($preAuth, 'Code') && $preAuth->Code !== 200) || $preAuth->Status == 'FAILED') {
$errorMessage = $this->get('translator')->trans('mangopay.error.'.$preAuth->ResultCode);

return new JsonResponse(array(
return new JsonResponse([
'success' => false,
'message' => $errorMessage,
));
]);
}
// Handle secure mode
if (property_exists($preAuth, 'SecureModeNeeded') && $preAuth->SecureModeNeeded == 1) {
return new JsonResponse(array(
'success' => true,
return new JsonResponse([
'success' => true,
'redirect' => $preAuth->SecureModeRedirectURL,
));
]);
}

// store payin transaction
Expand All @@ -134,9 +134,9 @@ public function paymentFinalizeAction(Request $request, $orderId, $cardId)
$this->get('translator')->trans('appventus_mangopay.alert.pre_authorisation.success')
);

return new JsonResponse(array(
return new JsonResponse([
'success' => true,
));
]);
}

/**
Expand Down Expand Up @@ -193,22 +193,24 @@ public function paymentFinalizeSecureAction(Request $request, $orderId)
$this->get('translator')->trans('appventus_mangopay.alert.pre_authorisation.success')
);

return $this->redirect($this->get('appventus_mangopay.payment_helper')->generateSuccessUrl());
return $this->redirect($this->get('appventus_mangopay.payment_helper')->generateSuccessUrl($orderId));
}

/**
* @param Request $request The request
* @param int $orderId
*
* This method shows the congratulations
*
* @Route("/success", name="appventus_mangopaybundle_payment_success")
* @Route("/success/{orderId}", name="appventus_mangopaybundle_payment_success")
*
* @return Response
*/
public function successAction(Request $request)
public function successAction(Request $request, $orderId)
{
return $this->render(
'AppVentusMangopayBundle::success.html.twig'
'AppVentusMangopayBundle::success.html.twig',
['orderId' => $orderId]
);
}
}
21 changes: 11 additions & 10 deletions Helper/PaymentHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ public function prepareCardRegistrationCallback(User $user, Order $order)

$redirect = $this->router->generate(
'appventus_mangopaybundle_payment_finalize',
array(
[
'orderId' => $order->getId(),
'cardId' => $mangoCardRegistration->Id,
)
'cardId' => $mangoCardRegistration->Id,
]
);

$successRedirect = $this->generateSuccessUrl();
$successRedirect = $this->generateSuccessUrl($order->getId());

return array(
return [
'callback' => 'payAjaxOrRedirect("'
.$redirect.'", "'
.$redirect.'", "'
.$cardRegistrationURL.'", "'
.$preregistrationData.'", "'
.$accessKey.'", "'
.$successRedirect.'")',
);
];
}

/**
Expand Down Expand Up @@ -110,9 +110,9 @@ public function createPreAuthorisation(CardRegistration $updatedCardRegister, Us
$cardPreAuthorisation->SecureMode = 'DEFAULT';
$cardPreAuthorisation->SecureModeReturnURL = $this->router->generate(
'appventus_mangopaybundle_payment_finalize_secure',
array(
[
'orderId' => $order->getId(),
),
],
true
);

Expand All @@ -125,6 +125,7 @@ public function createPreAuthorisation(CardRegistration $updatedCardRegister, Us

return $preAuth;
}

/**
* execute a pre authorisation.
*
Expand Down Expand Up @@ -195,8 +196,8 @@ public function cancelPreAuthForOrder(Order $order, CardPreAuthorisation $preAut
}
}

public function generateSuccessUrl()
public function generateSuccessUrl($orderId)
{
return $this->router->generate('appventus_mangopaybundle_payment_success');
return $this->router->generate('appventus_mangopaybundle_payment_success', ['orderId' => $orderId]);
}
}

0 comments on commit 25ef9a0

Please sign in to comment.