Skip to content

Commit

Permalink
Merge pull request #601 from krokedil/develop-hpp-change-payment-method
Browse files Browse the repository at this point in the history
Retrieve Klarna ID from session for subscription
  • Loading branch information
MichaelBengtsson authored Aug 12, 2024
2 parents 85d8a01 + 3886984 commit 88f5e64
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion classes/class-kco-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,12 @@ private function check_if_eu( $store_base_location ) {
public function process_embedded_payment_handler( $order_id ) {
// Get the Klarna order ID.
$order = wc_get_order( $order_id );
if ( ! empty( $order ) ) {

// For the initial subscription, the Klarna order ID should always exist in the session.
// This also applies to (pending) renewal subscription since existing Klarna order ID is no longer valid for the renewal, we must retrieve it from the session, not the order.
$is_subscription = function_exists( 'wcs_order_contains_subscription' ) && wcs_order_contains_subscription( $order, array( 'parent', 'resubscribe', 'switch', 'renewal' ) );

if ( ! empty( $order ) && ! $is_subscription ) {
$klarna_order_id = $order->get_meta( '_wc_klarna_order_id', true );
}
$klarna_order_id = ! empty( $klarna_order_id ) ? $klarna_order_id : WC()->session->get( 'kco_wc_order_id' );
Expand Down

0 comments on commit 88f5e64

Please sign in to comment.