Skip to content

Commit

Permalink
External payment methods
Browse files Browse the repository at this point in the history
  • Loading branch information
iverok committed Jun 4, 2024
1 parent 09f4f4a commit 7700f38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Vipps.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ public function payment_gateway_filter ($gateways) {
$order = $orderid ? wc_get_order($orderid) : null;
if (is_a($order, 'WC_Order')) {
$isavipps = $order->get_meta('_vipps_init_timestamp');
if ($isavipps) unset($gateways['vipps']);
// Existing override that allows repayment. IOK 2024-06-04
$allow_repayment = class_exists('\Site\Plugins\WooVipps\WooVippsPayForOrder');
$allow_repayment = $isavipps ? apply_filters('woo_vipps_allow_repayment', $allow_repayment, $order) : true;
if ($isavipps && !$allow_repayment) unset($gateways['vipps']);
}
}
return $gateways;
Expand Down
11 changes: 9 additions & 2 deletions VippsCheckout.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ public function choose_other_gw () {
$this->log(__("No session choosing other gateway from Vipps Checkout", 'woo-vipps'), 'error');
}

$current_pending = is_a(WC()->session, 'WC_Session') ? WC()->session->get('vipps_checkout_current_pending') : false;

# If we got here, we actually have shipping information already in place, so we can continue with the order directly!
$paymentdetails = WC_Gateway_Vipps::instance()->get_payment_details($order);
Expand All @@ -199,7 +200,8 @@ public function choose_other_gw () {
$url = $order->get_checkout_payment_url();

// This makes sure there is no "current vipps checkout" order, as this order is no longer payable at Vipps.
$this->abandonVippsCheckoutOrder(false);
// Actually, don't do this because it will most likely just create more spurious orders while this remains unpayable. IOK 2024-06-04
// $this->abandonVippsCheckoutOrder(false);
wp_redirect($url);
exit();
}
Expand Down Expand Up @@ -319,7 +321,9 @@ public function vipps_ajax_checkout_start_session () {
$token = "";

// First, check that we haven't already done this like in another window or something:
$session = $this->vipps_checkout_current_pending_session();
// IOK 2024-06-04 This also happens when using the back button! Sometimes!
$sessioninfo = $this->vipps_checkout_current_pending_session();

if (isset($sessioninfo['redirect'])) {
$redirect = $sessioninfo['redirect'];
}
Expand All @@ -329,6 +333,7 @@ public function vipps_ajax_checkout_start_session () {
$url = $src;
}
// And if we do, just return what we have. NB: This *should not happen*.
// IOK 2025-05-04 what are you talking about IOK, this absolutely happens e.g. when using the backbutton to a page starting the orders.
if ($url || $redir) {
$current_pending = is_a(WC()->session, 'WC_Session') ? WC()->session->get('vipps_checkout_current_pending') : false;
return wp_send_json_success(array('ok'=>1, 'msg'=>'session started', 'src'=>$url, 'redirect'=>$redir, 'token'=>$token, 'orderid'=>$current_pending));
Expand Down Expand Up @@ -658,6 +663,7 @@ function vipps_checkout_shortcode ($atts, $content) {
// we can open the iframe directly. Otherwise, the form we are going to output will
// create the iframe after a button press which will create a new order.
$sessioninfo = $this->vipps_checkout_current_pending_session();

$out = ""; // Start generating output already to make debugging easier

// This is the current pending order id, if it exists. Will be used to restart orders etc . IOK 2023-08-15 FIXME
Expand Down Expand Up @@ -726,6 +732,7 @@ public function cart_changed() {
}

public function abandonVippsCheckoutOrder($order) {

if (WC()->session) {
WC()->session->set('vipps_checkout_current_pending',0);
WC()->session->set('vipps_address_hash', false);
Expand Down

0 comments on commit 7700f38

Please sign in to comment.