Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/theyoungdesigners_com/modules/storeStripe/ |
Upload File : |
<?php
// https://docs.stripe.com/payments/quickstart?lang=php
namespace modules\storeStripe;
class main extends \moduleMain {
use \modules\input\traits {
\modules\input\traits::__construct as __ConstructInput;
}
use \modules\database\traits {
\modules\database\traits::__construct as __ConstructDatabase;
}
use \modules\output\traits {
\modules\output\traits::__construct as __ConstructOutput;
}
protected $view;
protected $model_order;
protected $model_stripe;
protected $sandboxmode;
public function __construct() {
parent::__construct(__DIR__);
$this->__ConstructInput();
$this->__ConstructDatabase();
$this->__ConstructOutput();
$this->view = $GLOBALS['loader']->getView('stripe_view', __DIR__);
$this->model_order = $this->loadModel('order_model', 'store');
$this->model_stripe = $this->loadModel('stripe_model');
}
public function Activate() {
hook_add('html.prepare', [$this, '__head']);
hook_add('template.store.checkout.COL5', [$this, '__column5']);
hook_add('template.store.checkout.COL6', [$this, '__column6']);
hook_add('template.store.checkout.COL7', [$this, '__column7']);
hook_add('template.store.fulfill.COL3', [$this, '__column3']);
hook_add('template.store.cart.COL4', [$this, '__column4'], 90); // add Secured by Stripe
hook_add('template.store.checkout.COL2', [$this, '__column4a'], 90); // add Secured by Stripe
hook_add('order.json.full', [$this, '__order_json']);
hook_add('order.json.payment', [$this, '__order_payment'], 90); // return the json for the delivery panel on checkout page
hook_add('order.approve.stripe', [$this, '__order_approve']);
}
public function __column3(&$html) { // payment method
$text = $this->view->Column3Text();
$this->view->UpdateHTML($html, 'COL3', $text);
}
public function __column4(&$html) {
$text = $this->view->Column4Text();
$this->view->UpdateHTML($html, 'COL4', $text);
}
public function __column4a(&$html) {
$text = $this->view->Column4aText();
$this->view->UpdateHTML($html, 'COL2', $text);
}
public function __column5(&$html) {
$text = $this->view->Column5Text();
$this->view->UpdateHTML($html, 'COL5', $text);
}
public function __column6(&$html) {
$text = $this->view->Column6Text();
$this->view->UpdateHTML($html, 'COL6', $text);
}
public function __column7(&$html) {
$text = $this->view->Column7Text();
$this->view->UpdateHTML($html, 'COL7', $text);
}
public function __head(&$theme) {
$id = $this->includeFile('https://js.stripe.com/v3/', 'stripe.js')->ext('js');
$base = $this->StaticUriModule(__DIR__);
$this->includeFile("$base/stripe_checkout.js")->depends('stripe.js');
}
private function getSandboxMode() {
$override = strtolower(trim($this->param('mode', '')));
if ($override == 'live' || $override == 'test') {
$this->sandboxmode = $override != 'live';
} else {
$this->sandboxmode = $this->settings['stripemode'] != 'live';
}
return $this->sandboxmode;
}
private function _loadInternalOrder($order_id) {
$this->model_order->OrderId($order_id);
$items = $this->model_order->AsHandleBars_Items();
// add current product details - upc, sku, etc
$items = hook_execute('product.overlay', $items);
$order_data = $this->model_order->AsHandleBars();
$order_data['order_id'] = $this->model_order->OrderId();
$order_data['items'] = $items;
$this->getSandboxMode();
$sk = $pk = '';
foreach(['pk', 'pk_test'] as $fieldname) {
if ($this->sandboxmode && strpos($this->settings[$fieldname], '_test_') !== FALSE) {
$pk = $this->settings[$fieldname];
break;
} elseif (!$this->sandboxmode && strpos($this->settings[$fieldname], '_test_') === FALSE) {
$pk = $this->settings[$fieldname];
break;
}
}
foreach(['sk', 'sk_test'] as $fieldname) {
if ($this->sandboxmode && strpos($this->settings[$fieldname], '_test_') !== FALSE) {
$sk = $this->settings[$fieldname];
break;
} elseif (!$this->sandboxmode && strpos($this->settings[$fieldname], '_test_') === FALSE) {
$sk = $this->settings[$fieldname];
break;
}
}
if ($sk == '' || $pk == '') {
$mode = $this->sandboxmode ? 'Sandbox' : 'Production';
throw new \Exception("$mode Stripe Keys are missing or incomplete");
}
$this->model_stripe
->ModelOrder($this->model_order)
->Currency('USD');
$this->model_stripe
->PublishedKey($pk)
->SecretKey($sk);
$this->model_stripe
->OrderData($order_data);
//return $order_data;
}
public function __order_payment(&$json, $order_id, $u_id) {
// the html is rendered by __order_json much earlier
$this->_loadInternalOrder($order_id);
$data = $this->model_stripe->InitializeSession();
$json = array_merge($json, $data);
$json['execute'] = 'stripe_payment';
}
public function __order_json(&$json, $order_id, $u_id) {
$json['custom_payment'] = 1;
$json['hide_confirm'] = 1;
$json['sandbox'] = $this->getSandboxMode() ? 1 : 0;
$json['auth'] = hook_execute('nonce.create', FALSE, 'stripes', $order_id, 600); // we don't use this expiry date
}
// https://docs.stripe.com/api/payment_intents/retrieve?lang=php
final function order_complete() {
// get order_id from auth - this may happen days later.
$auth = $this->param('auth', '');
$order_id = hook_execute( 'nonce.verify', FALSE, 'stripes', FALSE, $auth, TRUE ); // an expired auth is fine
$this->_loadInternalOrder($order_id);
$payment_intent = $this->param('payment_intent', '');
$redirect_status = $this->param('redirect_status', '');
if ($redirect_status == 'succeeded') {
$redirect_status = $this->model_stripe->finalizeOrder($payment_intent);
if (is_array($redirect_status)) {
$this->redirect($redirect_status['redirect']);
}
}
// failed - try again -
if (is_string($redirect_status)) {
// reload the page, display the noty
$this->redirect('/store/checkout?message=' . rawurlencode($redirect_status));
}
}
public function __order_approve($result, $params) {
// ($this->model_order still contains the order)
$this->model_stripe->approveStep();
}
}