Advertisement
Guest User

Untitled

a guest
Jan 25th, 2021
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. ---
  2. catalog/controller/payment/stripepro.php | 22 +++++++++++++++++++---
  3. system/library/esp/front.php | 13 ++++++++++++-
  4. 2 files changed, 31 insertions(+), 4 deletions(-)
  5.  
  6. diff --git a/catalog/controller/payment/stripepro.php b/catalog/controller/payment/stripepro.php
  7. index 56d22ed..2d81c97 100644
  8. --- a/catalog/controller/payment/stripepro.php
  9. +++ b/catalog/controller/payment/stripepro.php
  10. @@ -12,6 +12,7 @@ class ControllerPaymentStripePro extends Controller {
  11. parent::__construct($registry);
  12. $this->registry = $registry;
  13. $this->bird = new DBI\Bird($registry, $this->meta);
  14. + $this->logger = new Log('jwweb-stripepro.log');
  15. $this->dbi = ($dbi = $this->registry->get('dbi_catalog')) ? $dbi : new DBI\Catalog($this->registry, $this->meta);
  16. $this->full_route = $this->meta['route'] . $this->meta['ext_id'];
  17. $this->espro = ($espro = $this->registry->get('dbi_esp_front')) ? $espro : new ESP\Front($registry, $this->dbi, $this->meta);
  18. @@ -262,10 +263,25 @@ class ControllerPaymentStripePro extends Controller {
  19. $this->response->setOutput($json);
  20. }
  21.  
  22. + /*
  23. + * Return URL from the stripe checkout
  24. + * session_id = the session id that is assigned by stripe on their system
  25. + */
  26. public function checkoutWebhook() {
  27. - $this->load->model('checkout/order');
  28. - $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->getConfig('order_status_id'));
  29. - header('Location: ' . $this->url->link('checkout/success', '', 'SSL'));
  30. + try {
  31. + if(!$this->session->data['order_id']) {
  32. + throw new \Exception('Order id missing from session');
  33. + } else if($this->espro->getPaymentStatus($this->request->get['session_id']) == 'paid') {
  34. + $this->load->model('checkout/order');
  35. + $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->getConfig('order_status_id'));
  36. + header('Location: ' . $this->url->link('checkout/success', '', 'SSL'));
  37. + } else {
  38. + throw new \Exception('Error confirming payment for order (' . $this->session->data['order_id'] . ')');
  39. + }
  40. + } catch(Exception $e) {
  41. + $this->logger->write($e->getMessage());
  42. + header('Location: ' . $this->url->link('checkout/failure', '', 'SSL'));
  43. + }
  44. }
  45.  
  46. private function parseGet($var, $get) {
  47. diff --git a/system/library/esp/front.php b/system/library/esp/front.php
  48. index 6303b36..5b68f84 100644
  49. --- a/system/library/esp/front.php
  50. +++ b/system/library/esp/front.php
  51. @@ -218,6 +218,17 @@ final class Front {
  52. return $res;
  53. }
  54.  
  55. + public function getPaymentStatus($stripe_session_id){
  56. + require_once($this->meta['stripe_path']);
  57. + if($this->getConfig('transaction_mode')) {
  58. + \Stripe\Stripe::setApiKey($this->getConfig('live_private'));
  59. + } else {
  60. + \Stripe\Stripe::setApiKey($this->getConfig('test_private'));
  61. + }
  62. + $session = \Stripe\Checkout\Session::retrieve($stripe_session_id);
  63. + return $session->payment_status;
  64. + }
  65. +
  66. public function sessionPost() {
  67. $json = array();
  68. $this->load->language($this->full_route);
  69. @@ -276,7 +287,7 @@ final class Front {
  70. $session = \Stripe\Checkout\Session::create([
  71. 'payment_method_types' => ['card'],
  72. 'line_items' => $d2,
  73. - 'success_url' => $d3,
  74. + 'success_url' => $d3 . '&session_id={CHECKOUT_SESSION_ID}',
  75. 'cancel_url' => $d4,
  76. 'customer_email' => $order_info['email'],
  77. 'payment_intent_data' => [
  78. --
  79. 2.10.5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement