Klarna による支払い方法を受け付ける
世界で普及している後払いの支払い方法である Klarna を受け付ける方法をご紹介します。
Unified line items with Klarna
To optimize approval rates when you integrate with Klarna, include line_
data to represent what’s in a shopper’s cart. For early access, see Payments line items.
Klarna on the Express Checkout Element
Klarna on the Express Checkout Element is currently in private preview with limited availability. Reach out here to request access.
Stripe users can use the Payment Intents API—a single integration path for creating payments using any supported method—to accept Klarna payments from customers in Klarna’s supported countries.
Klarna is a single use, immediate notification payment method that requires customers to authenticate their payment. Customers are redirected to a Klarna page, where they select among multiple payment options (immediate full payment, payment in installments, or deferred payment). When the customer accepts the terms, Klarna guarantees that the funds are available to the customer and transfers the funds to your Stripe account. The customer repays Klarna according to their selected payment option.
注
導入を開始する前に、支払い方法の設定に移動して、アカウントで Klarna が使用可能であることを確認してください。
PaymentIntent を作成するサーバー側
A PaymentIntent is an object that represents your intent to collect payment from a customer and tracks the lifecycle of the payment process through each stage. First, create a PaymentIntent
on your server.
If you already have an integration using the Payment Intents API, add klarna
to the list of payment method types for your PaymentIntent
.
Klarna requires only customer currency. If you pass the optional shipping parameter, ensure these fields are defined and not empty: name
, address.
, city
, country
, and postal_
.
client secret を取得する
PaymentIntent には、client secret が含まれています。これは、支払いプロセスを安全に完了するためにクライアント側で使用されます。client secret をクライアント側に渡す際は、いくつかの方法を使用できます。
Stripe に支払いを送信するクライアント側
In this step, you’ll complete Klarna payments on the client with Stripe.js.
Stripe.js を設定する
顧客が Klarna での支払いをクリックするときは、Stripe.js を使用してその支払いを Stripe に送信することをお勧めします。Stripe.js は、支払いフローを構築するための Stripe の基本的な JavaScript ライブラリです。これにより、以下で説明するリダイレクトなどの複雑な処理が自動的に行われ、今後、組み込みを他の支払い方法にも簡単に拡張できます。Stripe.js スクリプトを HTML ファイルのヘッダーに追加することで、決済ページにこのスクリプトを含めます。
<head> <title>Checkout</title> <script src="https://js.stripe.com/v3/"></script> </head>
決済ページで以下の JavaScript を使用して、Stripe.js のインスタンスを作成します。
// Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys var stripe = Stripe(
);'pk_test_TYooMQauvdEDq54NiTphI7jx'
Rather than sending the entire PaymentIntent object to the client, use its client secret from step 2. This is different from your API keys that authenticate Stripe API requests.
それでも、client secret は支払いを完了できるため、慎重に扱う必要があります。記録したり、URL に埋め込んだり、その顧客以外に公開されることがないようにしてください。
Use stripe.confirmKlarnaPayment to handle the redirect away from your page and to complete the payment. Add a return_url to this function to indicate where Stripe should redirect the user after they complete the payment on the Klarna website or mobile application.
On Klarna’s payments page, the customer selects among the payment options available in their market. See the table on the overview page for availability by market. You can’t limit or pre-select payment options on the Klarna payments page—deferring this choice to the consumer maximizes their opportunity to transact with you.
// Redirects away from the client const {error} = await stripe.confirmKlarnaPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}',{ return_url: 'https://example.com/checkout/complete', } ); if (error) { // Inform the customer that there was an error. }
顧客が支払いを送信すると、Stripe は顧客を return_
にリダイレクトし、以下の URL クエリーパラメーターを含めます。返品ページでは、これらを使用して PaymentIntent のステータスを取得し、顧客に支払いステータスを表示できます。
return_
を指定する際に、返品ページで使用する独自のクエリパラメーターを追加することもできます。
パラメーター | 説明 |
---|---|
payment_ | PaymentIntent の一意の識別子。 |
payment_ | The client secret of the PaymentIntent object. For subscription integrations, this client_secret is also exposed on the Invoice object via confirmation_ |
顧客が自社のサイトにリダイレクトされたら、payment_
を使用して PaymentIntent をクエリし、顧客に取引ステータスを表示できます。
You can find details about the Klarna payment option the customer selected on the charge
in the payment_method_details property. There are four possible values: pay_
, pay_
, pay_
, and pay_
. See our Klarna overview page for more information on these options.
You can also find the locale used to localize Klarna’s payments page under the payment_method_details property.
{ "charges": { "data": [ { "payment_method_details": { "klarna": { "payment_method_category": "pay_in_installments", "preferred_locale": "en-US" }, "type": "klarna" }, "id": "src_16xhynE8WzK49JbAs9M21jaR", "object": "source", "amount": 1099, "client_secret": "src_client_secret_UfwvW2WHpZ0s3QEn9g5x7waU",
Klarna の組み込みをテストする
Below, we have specially selected test data for the currently supported customer countries. In a sandbox, Klarna approves or denies a transaction based on the supplied email address.
実働環境のテストのために、現地通貨の金額 3500
を使用して、融資以外のすべての Klarna 支払いオプションをテストできます。たとえば、イタリアでの「3 回払い」をテストする場合は、35.00 EUR の取引を使用できます。
2 段階認証
6 桁の数字であれば、2 段階認証コードとして有効です。999999
を使用すると、認証は失敗します。
返済方法
Klarna のフロー内では、以下のテスト値を使用し、さまざまな返済方法を試すことができます。
タイプ | 値 |
---|---|
口座引き落とし | DE11520513735120710131 |
銀行振込 | デモの銀行 |
クレジットカード |
|
Debit Card |
|
失敗した支払い
Klarna は、取引を受け付けるか拒否するかを決定する際に複数の要因を考慮します (買い手が Klarna を使用している期間、顧客が返済する必要のある未払い額、現在の注文の金額など)。
When the customer selects a deferred payment method, Klarna performs a risk assessment before accepting the transaction. Klarna might decline the transaction due to unsatisfactory risk assessment result, the transaction amount involved, or the customer having a large outstanding debt. As such, we recommend that you present additional payment options such as card
in your checkout flow. In these cases, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions to requires_
.
Customers are expected to complete the payment within 48 hours after they’re redirected to the Klarna site. If no action is taken after 48 hours, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions from requires_
to requires_
.
このようなケースでは、決済フローに表示される別の支払いオプションで再試行するように顧客に通知します。
Klarna のレート制限
API requests to Klarna are subject to additional rate limits beyond Stripe’s API-wide rate limits. These limits can differ depending on the shape of the API requests that you make. In general, if you make more than around 360 requests per minute, you may see some rate limiting in the form of responses with HTTP status code 400
or 402
. Please contact us for more details if you’re concerned that your usage may reach these levels, as Klarna may be able to increase these limits on a case by case basis.
エラーメッセージ
Failed Klarna payments normally return one of the following failure codes. These codes show in the last_payment_error API object.
注意
Before the 2023-08-16
API version, every Klarna error reported as payment_intent_authentication_failure. Make sure your API version is up to date to see the detailed errors listed below.
エラーコード | 説明 |
---|---|
payment_method_customer_decline | 顧客が Klarna のページで購入をキャンセルしました |
payment_method_provider_decline | Klarna が顧客の支払いを拒否しました |
payment_intent_payment_attempt_expired | 顧客が Klarna のページで購入を完了しないまま、支払いセッションの有効期限が切れました |
payment_method_not_available | Klarna を使用しようとしたときに予期しないエラーが発生しました |