Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce Klarna PM #7282

Merged
merged 20 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions assets/images/payment-methods/klarna.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions client/additional-methods-setup/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const upeMethods = [
'affirm',
'afterpay_clearpay',
'jcb',
'klarna',
];

export const upeCapabilityStatuses = {
Expand Down
2 changes: 2 additions & 0 deletions client/checkout/blocks/upe-split.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
PAYMENT_METHOD_NAME_SOFORT,
PAYMENT_METHOD_NAME_AFFIRM,
PAYMENT_METHOD_NAME_AFTERPAY,
PAYMENT_METHOD_NAME_KLARNA,
} from '../constants.js';
import { getSplitUPEFields } from './upe-split-fields';
import { getDeferredIntentCreationUPEFields } from './upe-deferred-intent-creation/payment-elements';
Expand All @@ -46,6 +47,7 @@ const upeMethods = {
sofort: PAYMENT_METHOD_NAME_SOFORT,
affirm: PAYMENT_METHOD_NAME_AFFIRM,
afterpay_clearpay: PAYMENT_METHOD_NAME_AFTERPAY,
klarna: PAYMENT_METHOD_NAME_KLARNA,
};

const enabledPaymentMethodsConfig = getUPEConfig( 'paymentMethodsConfig' );
Expand Down
2 changes: 2 additions & 0 deletions client/checkout/classic/upe-split.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
PAYMENT_METHOD_NAME_SOFORT,
PAYMENT_METHOD_NAME_AFFIRM,
PAYMENT_METHOD_NAME_AFTERPAY,
PAYMENT_METHOD_NAME_KLARNA,
SHORTCODE_SHIPPING_ADDRESS_FIELDS,
SHORTCODE_BILLING_ADDRESS_FIELDS,
} from '../constants';
Expand Down Expand Up @@ -657,6 +658,7 @@ jQuery( function ( $ ) {
PAYMENT_METHOD_NAME_SOFORT,
PAYMENT_METHOD_NAME_AFFIRM,
PAYMENT_METHOD_NAME_AFTERPAY,
PAYMENT_METHOD_NAME_KLARNA,
paymentMethodsConfig.card !== undefined && PAYMENT_METHOD_NAME_CARD,
].filter( Boolean );
const checkoutEvents = wcpayPaymentMethods
Expand Down
2 changes: 2 additions & 0 deletions client/checkout/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const PAYMENT_METHOD_NAME_SOFORT = 'woocommerce_payments_sofort';
export const PAYMENT_METHOD_NAME_AFFIRM = 'woocommerce_payments_affirm';
export const PAYMENT_METHOD_NAME_AFTERPAY =
'woocommerce_payments_afterpay_clearpay';
export const PAYMENT_METHOD_NAME_KLARNA = 'woocommerce_payments_klarna';
export const PAYMENT_METHOD_NAME_UPE = 'woocommerce_payments_upe';
export const PAYMENT_METHOD_NAME_PAYMENT_REQUEST =
'woocommerce_payments_payment_request';
Expand All @@ -30,6 +31,7 @@ export function getPaymentMethodsConstants() {
PAYMENT_METHOD_NAME_AFFIRM,
PAYMENT_METHOD_NAME_AFTERPAY,
PAYMENT_METHOD_NAME_CARD,
PAYMENT_METHOD_NAME_KLARNA,
];
}

Expand Down
1 change: 1 addition & 0 deletions client/components/payment-method-details/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const formatDetails = ( payment ) => {
);
case 'affirm':
case 'afterpay_clearpay':
case 'klarna':
default:
return <Fragment />;
}
Expand Down
32 changes: 32 additions & 0 deletions client/payment-methods-map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import BankDebitIcon from 'assets/images/payment-methods/bank-debit.svg?asset';
import AffirmIcon from 'assets/images/payment-methods/affirm.svg?asset';
import AfterpayIcon from 'assets/images/payment-methods/afterpay.svg?asset';
import JCBIcon from 'assets/images/payment-methods/jcb.svg?asset';
import KlarnaIcon from 'assets/images/payment-methods/klarna.svg?asset';
kalessil marked this conversation as resolved.
Show resolved Hide resolved

const iconComponent = ( src: string, alt: string ): ReactImgFuncComponent => (
props
Expand Down Expand Up @@ -247,6 +248,37 @@ const PaymentMethodInformationObject: Record<
'woocommerce-payments'
),
},
klarna: {
id: 'klarna',
label: __( 'Klarna', 'woocommerce-payments' ),
brandTitles: {
affirm: __( 'Klarna', 'woocommerce-payments' ),
},
description: __(
// translators: %s is the store currency.
// TODO: Is "Available to all customers paying in %s." correct for BNPLs given the introduction of domestic check for PMs?.
kalessil marked this conversation as resolved.
Show resolved Hide resolved
'Allow customers to pay over time with Klarna. Available to all customers paying in %s.',
'woocommerce-payments'
),
icon: iconComponent( KlarnaIcon, 'Klarna' ),
currencies: [
kalessil marked this conversation as resolved.
Show resolved Hide resolved
'AUD',
'CAD',
'CHF',
'CZK',
'DKK',
'EUR',
'GBP',
'NOK',
'NZD',
'PLN',
'SEK',
'USD',
],
stripe_key: 'klarna_payments',
allows_manual_capture: false,
allows_pay_later: true,
},
};

export default PaymentMethodInformationObject;
1 change: 1 addition & 0 deletions client/payment-methods/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum PAYMENT_METHOD_IDS {
CARD = 'card',
CARD_PRESENT = 'card_present',
EPS = 'eps',
KLARNA = 'klarna',
GIROPAY = 'giropay',
IDEAL = 'ideal',
LINK = 'link',
Expand Down
3 changes: 2 additions & 1 deletion client/types/charges.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export interface PaymentMethodDetails {
| 'ideal'
| 'p24'
| 'sepa_debit'
| 'sofort';
| 'sofort'
| 'klarna';
KarlisJ marked this conversation as resolved.
Show resolved Hide resolved
}

export type OutcomeRiskLevel =
Expand Down
1 change: 1 addition & 0 deletions client/types/payment-methods.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type PaymentMethod =
| 'card'
| 'card_present'
| 'eps'
| 'klarna'
| 'giropay'
| 'ideal'
| 'p24'
Expand Down
2 changes: 2 additions & 0 deletions client/utils/account-fees.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ export const getTransactionsPaymentMethodName = (
return __( 'Affirm transactions', 'woocommerce-payments' );
case 'afterpay_clearpay':
return __( 'Afterpay transactions', 'woocommerce-payments' );
case 'klarna':
return __( 'Klarna transactions', 'woocommerce-payments' );
default:
return __( 'Unknown transactions', 'woocommerce-payments' );
}
Expand Down
1 change: 1 addition & 0 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public function __construct(
'link' => 'link_payments',
'affirm' => 'affirm_payments',
'afterpay_clearpay' => 'afterpay_clearpay_payments',
'klarna' => 'klarna_payments',
];

// WooPay utilities.
Expand Down
3 changes: 3 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use WCPay\Payment_Methods\Bancontact_Payment_Method;
use WCPay\Payment_Methods\Becs_Payment_Method;
use WCPay\Payment_Methods\Giropay_Payment_Method;
use WCPay\Payment_Methods\Klarna_Payment_Method;
use WCPay\Payment_Methods\P24_Payment_Method;
use WCPay\Payment_Methods\Sepa_Payment_Method;
use WCPay\Payment_Methods\Sofort_Payment_Method;
Expand Down Expand Up @@ -396,6 +397,7 @@ public static function init() {
include_once __DIR__ . '/payment-methods/class-affirm-payment-method.php';
include_once __DIR__ . '/payment-methods/class-afterpay-payment-method.php';
include_once __DIR__ . '/payment-methods/class-jcb-payment-method.php';
include_once __DIR__ . '/payment-methods/class-klarna-payment-method.php';
KarlisJ marked this conversation as resolved.
Show resolved Hide resolved
include_once __DIR__ . '/class-wc-payment-token-wcpay-sepa.php';
include_once __DIR__ . '/class-wc-payments-status.php';
include_once __DIR__ . '/class-wc-payments-token-service.php';
Expand Down Expand Up @@ -505,6 +507,7 @@ public static function init() {
Affirm_Payment_Method::class,
Afterpay_Payment_Method::class,
JCB_Payment_Method::class,
Klarna_Payment_Method::class,
KarlisJ marked this conversation as resolved.
Show resolved Hide resolved
];
if ( WC_Payments_Features::is_upe_deferred_intent_enabled() ) {
$payment_methods = [];
Expand Down
2 changes: 2 additions & 0 deletions includes/constants/class-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Payment_Method extends Base_Constant {
const US_BANK_ACCOUNT = 'us_bank_account';
const AFFIRM = 'affirm';
const AFTERPAY = 'afterpay_clearpay';
const KLARNA = 'klarna';

const IPP_ALLOWED_PAYMENT_METHODS = [
self::CARD_PRESENT,
Expand All @@ -44,5 +45,6 @@ class Payment_Method extends Base_Constant {
const BNPL_PAYMENT_METHODS = [
self::AFFIRM,
self::AFTERPAY,
self::KLARNA,
];
}
45 changes: 45 additions & 0 deletions includes/payment-methods/class-klarna-payment-method.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Class Affirm_Payment_Method
*
* @package WCPay\Payment_Methods
*/

namespace WCPay\Payment_Methods;

use WC_Payments_Token_Service;
use WC_Payments_Utils;
use WCPay\MultiCurrency\MultiCurrency;

/**
* Affirm Payment Method class extending UPE base class
*/
class Klarna_Payment_Method extends UPE_Payment_Method {

const PAYMENT_METHOD_STRIPE_ID = 'klarna';

/**
* Constructor for link payment method
*
* @param WC_Payments_Token_Service $token_service Token class instance.
*/
public function __construct( $token_service ) {
parent::__construct( $token_service );
$this->stripe_id = self::PAYMENT_METHOD_STRIPE_ID;
$this->title = __( 'Klarna', 'woocommerce-payments' );
$this->is_reusable = false;
$this->icon_url = plugins_url( 'assets/images/payment-methods/klarna.svg', WCPAY_PLUGIN_FILE );
$this->currencies = [ 'AUD', 'CAD', 'CHF', 'CZK', 'DKK', 'EUR', 'GBP', 'NOK', 'NZD', 'PLN', 'SEK', 'USD' ];
$this->accept_only_domestic_payment = true;
$this->countries = [ 'AU', 'AT', 'BE', 'CA', 'CZ', 'DK', 'FI', 'FR', 'GR', 'DE', 'IE', 'IT', 'NL', 'NZ', 'NO', 'PL', 'PT', 'ES', 'SE', 'CH', 'GB', 'US' ];
KarlisJ marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns testing credentials to be printed at checkout in test mode.
*
* @return string
*/
public function get_testing_instructions() {
return '';
}
}
1 change: 1 addition & 0 deletions includes/payment-methods/class-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ public function get_upe_available_payment_methods() {
$available_methods[] = Link_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Affirm_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Afterpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID;
$available_methods[] = Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID;

// List JCB method for Japanese account only.
if ( 'JP' === $this->account->get_account_country() ) {
Expand Down