1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
<?php
defined( 'ABSPATH' ) || exit();
if ( ! class_exists( 'WC_Payment_Gateway_Stripe_Local_Payment' ) ) {
return;
}
class WC_Payment_Gateway_Stripe_Klarna extends WC_Payment_Gateway_Stripe_Local_Payment {
protected $payment_method_type = 'klarna';
use WC_Stripe_Local_Payment_Intent_Trait;
public function __construct() {
$this->local_payment_type = 'klarna';
$this->currencies = array( 'EUR', 'SEK', 'NOK', 'DKK', 'GBP', 'USD' );
$this->countries = $this->limited_countries = array( 'US', 'AT', 'FI', 'DE', 'NL', 'DK', 'NO', 'SE', 'GB', 'BE', 'ES', 'IT', 'FR', 'IE' );
$this->id = 'stripe_klarna';
$this->tab_title = __( 'Klarna', 'woo-stripe-payment' );
$this->token_type = 'Stripe_Local';
$this->method_title = __( 'Klarna', 'woo-stripe-payment' );
$this->method_description = __( 'Klarna gateway that integrates with your Stripe account.', 'woo-stripe-payment' );
parent::__construct();
$this->template_name = 'klarna-v2.php';
$this->icon = stripe_wc()->assets_url( 'img/' . $this->get_option( 'icon' ) . '.svg' );
}
public function get_required_parameters() {
return apply_filters( 'wc_stripe_klarna_get_required_parameters', array(
'USD' => array( 'US' ),
'EUR' => array( 'AT', 'FI', 'DE', 'NL', 'BE', 'ES', 'IT', 'FR', 'IE' ),
'DKK' => array( 'DK' ),
'NOK' => array( 'NO' ),
'SEK' => array( 'SE' ),
'GBP' => array( 'GB' ),
), $this );
}
public function validate_local_payment_available( $currency, $billing_country, $total ) {
if ( $billing_country ) {
$params = $this->get_required_parameters();
return isset( $params[ $currency ] ) && in_array( $billing_country, $params[ $currency ] ) !== false;
}
return false;
}
public function add_stripe_order_args( &$args, $order ) {
$args['payment_method_options'] = array(
'klarna' => array(
'preferred_locale' => $this->get_formatted_locale_from_order( $order )
)
);
}
private function get_formatted_locale_from_order( $order ) {
$country = $order->get_billing_country();
switch ( $country ) {
case 'US':
$locale = 'en-US';
break;
case 'GB':
$locale = 'en-GB';
break;
case 'AT':
$locale = 'de-AT';
break;
case 'BE':
$locale = 'fr-BE';
break;
case 'DK':
$locale = 'da-DK';
break;
case 'NO':
$locale = 'nb-NO';
break;
case 'SE':
$locale = 'sv-SE';
break;
default:
$locale = strtolower( $country ) . '-' . strtoupper( $country );
}
return $locale;
}
public function get_local_payment_settings() {
return wp_parse_args(
array(
'charge_type' => array(
'type' => 'select',
'title' => __( 'Charge Type', 'woo-stripe-payment' ),
'default' => 'capture',
'class' => 'wc-enhanced-select',
'options' => array(
'capture' => __( 'Capture', 'woo-stripe-payment' ),
'authorize' => __( 'Authorize', 'woo-stripe-payment' ),
),
'desc_tip' => true,
'description' => __( 'This option determines whether the customer\'s funds are captured immediately or authorized and can be captured at a later date.',
'woo-stripe-payment' ),
),
'icon' => array(
'title' => __( 'Icon', 'woo-stripe-payment' ),
'type' => 'select',
'options' => array(
'klarna' => __( 'Black text', 'woo-stripe-payment' ),
'klarna_pink' => __( 'Pink background black text', 'woo-stripe-payment' )
),
'default' => 'klarna_pink',
'desc_tip' => true,
'description' => __( 'This is the icon style that appears next to the gateway on the checkout page.', 'woo-stripe-payment' ),
)
),
parent::get_local_payment_settings()
);
}
}