# Klarna による支払い方法を受け付ける 世界で普及している後払いの支払い方法である Klarna を受け付ける方法をご紹介します。 [Klarna](https://docs.stripe.com/payments/klarna.md) では、顧客は決済時に Klarna アカウントにリダイレクトされます。Stripe をまだ導入していない場合は、Stripe Checkout を使用して[Stripe がオンラインで提供する決済ページを作成](https://docs.stripe.com/checkout/quickstart.md)し、ダッシュボードで[決済手段を設定](https://docs.stripe.com/payments/dashboard-payment-methods.md)することをお勧めします。 [Checkout Sessions API で Elements を使用](https://docs.stripe.com/payments/quickstart-checkout-sessions.md)して、Web サイトにカスタマイズされた決済画面を構築したり、モバイル導入を構築して WebView で決済を認証することもできます。 > 導入を開始する前に、[決済手段設定](https://dashboard.stripe.com/settings/payment_methods)に移動して、アカウントがKlarnaの対象であることを確認してください。 # Checkout > This is a Checkout for when payment-ui is checkout. View the full page at https://docs.stripe.com/payments/klarna/accept-a-payment?payment-ui=checkout. ## 決済手段を手動で一覧表示する [動的な決済手段](https://docs.stripe.com/payments/payment-methods/dynamic-payment-methods.md)の使用をお勧めします。ここでは、Stripe が各顧客に最も関連性の高い決済手段を動的に表示してコンバージョンを最大化するロジックを処理します。[決済手段](https://docs.stripe.com/payments/payment-methods/integration-options.md#listing-payment-methods-manually)を手動で一覧表示する場合は、[決済セッション](https://docs.stripe.com/api/checkout/sessions.md)の作成時に [payment_method_types](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-payment_method_types) で `klarna` を指定して、決済ページに Klarna を含めます。異なる通貨の `line_items` がある場合は、決済セッションを個別に作成する必要があります。 #### Stripe がオンラインで提供するページ ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price_data][currency]=eur" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=1099" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=klarna" \ --data-urlencode "success_url=https://example.com/success" ``` #### 埋め込みフォーム ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price_data][currency]=eur" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=1099" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=klarna" \ --data-urlencode "return_url=https://example.com/return" \ -d ui_mode=embedded_page ``` ## 実装内容をテストする 決済の導入をテストする際に、決済手段として Klarna を選択して、**決済する**ボタンをクリックします。テスト環境では、Klarna のリダイレクト内でさまざまな結果をシミュレーションできます。 > Klarna はセッションの追跡に クッキーを使用します。さまざまな顧客の所在地をテストするには、前のセッションで Klarna サンドボックスからログアウトし、関連するトリガーを使用します。 下記では、現在対応している顧客の国のテストデータを特別に選択しています。サンドボックスでは、Klarna は指定されたメールアドレスに基づいて取引を承認または拒否します。 #### オーストラリア | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 03-05-1994 | | 名 | テスト | John | | 姓 | Person-au | snow | | 町名・番地 | Wharf St | Silverwater Rd | | 番地等 | 4 | 1-5 | | 郵便番号 | 4877 | 2128 | | 市区町村 | Port Douglas | Silverwater | | 地域 | QLD | NSW | | 電話番号 | +61473752244 | +61473763254 | | メールアドレス | customer@email.au | customer+denied@email.au | #### オーストリア | | 承認済み | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-at | Person-at | | メールアドレス | customer@email.at | customer+denied@email.at | | 町名・番地 | Mariahilfer Straße | Mariahilfer Straße | | 番地 | 47 | 47 | | 市区町村 | Wien | Wien | | 郵便番号 | 1060 | 1060 | | 電話番号 | +4306762600456 | +4306762600745 | #### ベルギー | | 承認済み | 拒否済み | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-be | Person-be | | メールアドレス | customer@email.be | customer+denied@email.be | | 町名・番地 | Grote Markt | Grote Markt | | 番地 | 1 | 1 | | 市 | Brussel | Brussel | | 郵便番号 | 1000 | 1000 | | 電話番号 | +32485121291 | +32485212123 | #### カナダ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ca | Person-ca | | 町名・番地 | 2693 Byron Rd | 2693 Byron Rd | | 郵便番号 | V7H 1L9 | V7H 1L9 | | 市区町村 | North Vancouver | North Vancouver | | 地域 | BC | BC | | 電話番号 | +15197438620 | +15197308624 | | メールアドレス | customer@email.ca | customer+denied@email.ca | #### チェコ | | 承認 | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 01-01-1970 | 27-06-1992 | | 名 | テスト | テスト | | 姓 | Person-cz | Person-cz | | メールアドレス | customer@email.cz | customer+denied@email.cz | | 町名・番地 | Zazvorkova 1480/11 | Zázvorkova 1480/11 | | 郵便番号 | 155 00 | 155 00 | | 市区町村 | Praha | PRAHA 13 | | 電話番号 | +420771613715 | +420771623691 | #### デンマーク | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-dk | Person-dk | | メールアドレス | customer@email.dk | customer+denied@email.dk | | 町名・番地 | Dantes Plads | Nygårdsvej | | 番地 | 7 | 65 | | 市区町村 | København Ø | København Ø | | 郵便番号 | 1556 | 2100 | | 電話番号 | +4542555628 | +4552555348 | #### フィンランド | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1999 | 01-01-1999 | | 名 | テスト | Person FI | | 姓 | Person-fi | テスト | | メールアドレス | customer@email.fi | customer+denied@email.fi | | 町名・番地 | Mannerheimintie | Mannerheimintie | | 番地 | 34 | 34 | | 市区町村 | Helsinki | Helsinki | | 郵便番号 | 00100 | 00100 | | 電話番号 | +358401234567 | +358401234568 | #### フランス | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 10-07-1990 | 10-07-1990 | | 出生地 | パリ | パリ | | 名 | テスト | テスト | | 姓 | Person-fr | Person-fr | | メールアドレス | customer@email.fr | customer+denied@email.fr | | 町名・番地 | rue La Fayette | rue La Fayette | | 番地 | 33 | 33 | | 市区町村 | パリ | パリ | | 郵便番号 | 75009 | 75009 | | 電話番号 | +33689854321 | +33687984322 | #### ドイツ | | 承認済み | 拒否済み | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | 模擬 | テスト | | 姓 | 模擬 | Person-de | | メールアドレス | customer@email.de | customer+denied@email.de | | 町名・番地 | Neue Schönhauser Str. | Neue Schönhauser Str. | | 番地 | 2 | 2 | | 市 | Berlin | Berlin | | 郵便番号 | 10178 | 10178 | | 電話番号 | +49017614284340 | +49017610927312 | #### ギリシャ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 納税者番号 | 090000045 | 090000045 | | 生年月日 | 01-01-1960 | 11-11-1970 | | 名 | テスト | テスト | | 姓 | Person-gr | Test-gr | | メールアドレス | customer@email.gr | customer+denied@email.gr | | 町名・番地 | Kephisias | Baralo | | 番地 | 37 | 56 | | 郵便番号 | 151 23 | 123 67 | | 市区町村 | Athina | Athina | | 電話番号 | +306945553624 | +306945553625 | #### アイルランド | | 承認済み | 拒否 | | -------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ie | Person-ie | | メール | customer@email.ie | customer+denied@email.ie | | 町名・番地 | King Street South | King Street South | | 番地 | 30 | 30 | | 市区町村 | ダブリン | ダブリン | | EIR Code | D02 C838 | D02 C838 | | 電話番号 | +353855351400 | +353855351401 | #### イタリア | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 01-01-1980 | | 名 | テスト | テスト | | 姓 | Person-it | Person-it | | メールアドレス | customer@email.it | customer+denied@email.it | | 納税番号 | RSSBNC80A41H501B | RSSBNC80A41H501B | | 町名・番地 | Via Enrico Fermi | Via Enrico Fermi | | 番地 | 150 | 150 | | 市区町村 | Roma | Roma | | 郵便番号 | 00146 | 00146 | | 電話番号 | +393339741231 | +393312232389 | #### オランダ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nl | Person-nl | | メールアドレス | customer@email.nl | customer+denied@email.nl | | 町名・番地 | Osdorpplein | Osdorpplein | | 番地 | 137 | 137 | | 市区町村 | Amsterdam | Amsterdam | | 郵便番号 | 1068 SR | 1068 SR | | 電話番号 | +31689124321 | +31632167678 | #### ニュージーランド | | 承認 | 拒否 | | ------- | ------------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nz | Person-nz | | 町名・番地 | Mount Wellington Highway | Mount Wellington Highway | | 番地等 | 286 | 286 | | 郵便番号 | 6011 | 6011 | | 市区町村 | Auckland | Wellington | | 電話番号 | +6427555290 | +642993007712 | | メールアドレス | customer@email.nz | customer+denied@email.nz | #### ノルウェー | | 承認済み | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 01-08-1970 | 01-08-1970 | | 名 | Jane | テスト | | 姓 | テスト | Person-no | | メールアドレス | customer@email.no | customer+denied@email.no | | 個人番号 | NO1087000571 | NO1087000148 | | 町名・番地 | Edvard Munchs Plass | Sæffleberggate | | 番地 | 1 | 56 | | 市区町村 | Oslo | Oslo | | 郵便番号 | 0194 | 0563 | | 電話番号 | +4740123456 | +4740123457 | #### ポーランド | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 05-05-1967 | 05-05-1967 | | 名 | テスト | テスト | | 姓 | Person-pl | Person-pl | | 町名・番地 | Ul. Górczewska | Ul. Górczewska | | 番地等 | 124 | 124 | | 郵便番号 | 01-460 | 01-460 | | 市区町村 | Warszawa | Warszawa | | 電話番号 | +48795222223 | +48795223325 | | メールアドレス | customer@email.pl | customer+denied@email.pl | #### ポルトガル | | 承認 | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-pt | Person-pt | | 町名・番地 | Avenida Dom João II | Avenida Dom João II | | 番地等 | 40 | 40 | | 郵便番号 | 1990-094 | 1990-094 | | 市区町村 | Lisboa | Lisboa | | 電話番号 | +351935556731 | +351915593837 | | メールアドレス | customer@email.pt | customer+denied@email.pt | #### ルーマニア | | 承認されました | 拒否 | | ------------ | ----------------- | ------------------------ | | 生年月日 | 1970 年 12 月 25 日 | 1970 年 12 月 25 日 | | 名 | テスト | テスト | | 姓 | Person-ro | Person-ro | | メール | customer@email.ro | customer+denied@email.ro | | 町名・番地 | Drumul Taberei | Drumul Taberei | | 番地 | 35 | 35 | | 市区町村 | București | București | | セクター | Sectorul 6 | Sectorul 6 | | 郵便番号 | 061357 | 061357 | | 電話 | +40741209876 | +40707127444 | | 個人識別番号 (CNP) | 1701225193558 | | #### スペイン | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | DNI/NIE | 99999999R | 99999999R | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-es | Person-es | | メールアドレス | customer@email.es | customer+denied@email.es | | 町名・番地 | C. de Atocha | C. de Atocha | | 番地 | 27 | 27 | | 市区町村 | Madrid | Madrid | | 郵便番号 | 28012 | 28012 | | 電話番号 | +34672563009 | +34682425101 | #### スウェーデン | | 承認済み | 拒否 | | ------- | ----------------------- | ------------------------ | | 生年月日 | 21-03-1941 | 28-10-1941 | | 名 | Alice | テスト | | 姓 | テスト | Person-se | | メールアドレス | customer@email.se | customer+denied@email.se | | 町名・番地 | Södra Blasieholmshamnen | Karlaplan | | 番地 | 2 | 3 | | 市区町村 | Stockholm | Stockholm | | 郵便番号 | 11 148 | 11 460 | | 電話番号 | +46701740615 | +46701740620 | #### スイス | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1990 | 01-01-2000 | | 名 | 受付済み | 顧客 | | 姓 | Person-ch | Person-ch | | 町名・番地 | Augustinergasse | Bahnhofstrasse | | 番地等 | 2 | 77 | | 郵便番号 | 4051 | 8001 | | 市区町村 | Basel | Zürich | | 電話番号 | +41758680000 | +41758680001 | | メールアドレス | customer@email.ch | customer+denied@email.ch | #### イギリス | | 承認済み | 拒否 | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-uk | Person-uk | | メールアドレス | customer@email.uk | customer+denied@email.uk | | 町名・番地 | New Burlington Street | New Burlington Street | | 番地 | 10 | 10 | | アパート | Apt 214 | Apt 214 | | 郵便番号 | W1S 3BE | W1S 3BE | | 市区町村 | London | London | | 電話番号 | +447755564318 | +447355505530 | #### アメリカ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 07-10-1970 | 07-10-1970 | | 名 | テスト | テスト | | 姓 | Person-us | Person-us | | メールアドレス | customer@email.us | customer+denied@email.us | | 町名・番地 | Amsterdam Ave | Amsterdam Ave | | 番地 | 509 | 509 | | 市区町村 | New York | New York | | 州 | New York | New York | | 郵便番号 | 10024-3941 | 10024-3941 | | 電話番号 | +13106683312 | +13106354386 | 実働環境のテストのために、現地通貨の金額 `3500` を使用して、融資以外のすべての Klarna 支払いオプションをテストできます。たとえば、イタリアでの「3 回払い」をテストする場合は、35.00 EUR の取引を使用できます。 ### 2 段階認証 6 桁の数字であれば、2 段階認証コードとして有効です。`999999` を使用すると、認証は失敗します。 ### 返済方法 Klarna のフロー内では、以下のテスト値を使用し、さまざまな返済方法を試すことができます。 | タイプ | 値 | | -------- | ---------------------------------------------------------- | | 口座引き落とし | DE11520513735120710131 | | 銀行振込 | デモの銀行 | | クレジットカード | - 番号: 4111 1111 1111 1111 - CVV: 123 - 有効期限: 任意の将来日付 | | デビットカード | - カード番号:4012 8888 8888 1881 - CVV: 123 - 有効期限: 任意の将来日付 | # Elements > This is a Elements for when payment-ui is elements. View the full page at https://docs.stripe.com/payments/klarna/accept-a-payment?payment-ui=elements. ## 決済手段を手動で一覧表示する [動的な決済手段](https://docs.stripe.com/payments/payment-methods/dynamic-payment-methods.md)の使用をお勧めします。ここでは、Stripe が各顧客に最も関連性の高い決済手段を動的に表示してコンバージョンを最大化するロジックを処理します。[決済手段](https://docs.stripe.com/payments/payment-methods/integration-options.md#listing-payment-methods-manually)を手動で一覧表示する場合は、[決済セッション](https://docs.stripe.com/api/checkout/sessions.md)の作成時に [payment_method_types](https://docs.stripe.com/api/checkout/sessions/create.md#create_checkout_session-payment_method_types) で `klarna` を指定して、決済ページに Klarna を含めます。異なる通貨の `line_items` がある場合は、決済セッションを個別に作成する必要があります。 ```curl curl https://api.stripe.com/v1/checkout/sessions \ -u "<>:" \ -d "line_items[0][price_data][currency]=eur" \ -d "line_items[0][price_data][product_data][name]=T-shirt" \ -d "line_items[0][price_data][unit_amount]=1099" \ -d "line_items[0][quantity]=1" \ -d mode=payment \ -d "payment_method_types[0]=card" \ -d "payment_method_types[1]=klarna" \ --data-urlencode "return_url=https://example.com/return" \ -d ui_mode=elements ``` ## 実装内容をテストする 決済の導入をテストする際に、決済手段として Klarna を選択して、**決済する**ボタンをクリックします。テスト環境では、Klarna のリダイレクト内でさまざまな結果をシミュレーションできます。 > Klarna はセッションの追跡に クッキーを使用します。さまざまな顧客の所在地をテストするには、前のセッションで Klarna サンドボックスからログアウトし、関連するトリガーを使用します。 下記では、現在対応している顧客の国のテストデータを特別に選択しています。サンドボックスでは、Klarna は指定されたメールアドレスに基づいて取引を承認または拒否します。 #### オーストラリア | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 03-05-1994 | | 名 | テスト | John | | 姓 | Person-au | snow | | 町名・番地 | Wharf St | Silverwater Rd | | 番地等 | 4 | 1-5 | | 郵便番号 | 4877 | 2128 | | 市区町村 | Port Douglas | Silverwater | | 地域 | QLD | NSW | | 電話番号 | +61473752244 | +61473763254 | | メールアドレス | customer@email.au | customer+denied@email.au | #### オーストリア | | 承認済み | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-at | Person-at | | メールアドレス | customer@email.at | customer+denied@email.at | | 町名・番地 | Mariahilfer Straße | Mariahilfer Straße | | 番地 | 47 | 47 | | 市区町村 | Wien | Wien | | 郵便番号 | 1060 | 1060 | | 電話番号 | +4306762600456 | +4306762600745 | #### ベルギー | | 承認済み | 拒否済み | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-be | Person-be | | メールアドレス | customer@email.be | customer+denied@email.be | | 町名・番地 | Grote Markt | Grote Markt | | 番地 | 1 | 1 | | 市 | Brussel | Brussel | | 郵便番号 | 1000 | 1000 | | 電話番号 | +32485121291 | +32485212123 | #### カナダ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ca | Person-ca | | 町名・番地 | 2693 Byron Rd | 2693 Byron Rd | | 郵便番号 | V7H 1L9 | V7H 1L9 | | 市区町村 | North Vancouver | North Vancouver | | 地域 | BC | BC | | 電話番号 | +15197438620 | +15197308624 | | メールアドレス | customer@email.ca | customer+denied@email.ca | #### チェコ | | 承認 | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 01-01-1970 | 27-06-1992 | | 名 | テスト | テスト | | 姓 | Person-cz | Person-cz | | メールアドレス | customer@email.cz | customer+denied@email.cz | | 町名・番地 | Zazvorkova 1480/11 | Zázvorkova 1480/11 | | 郵便番号 | 155 00 | 155 00 | | 市区町村 | Praha | PRAHA 13 | | 電話番号 | +420771613715 | +420771623691 | #### デンマーク | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-dk | Person-dk | | メールアドレス | customer@email.dk | customer+denied@email.dk | | 町名・番地 | Dantes Plads | Nygårdsvej | | 番地 | 7 | 65 | | 市区町村 | København Ø | København Ø | | 郵便番号 | 1556 | 2100 | | 電話番号 | +4542555628 | +4552555348 | #### フィンランド | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1999 | 01-01-1999 | | 名 | テスト | Person FI | | 姓 | Person-fi | テスト | | メールアドレス | customer@email.fi | customer+denied@email.fi | | 町名・番地 | Mannerheimintie | Mannerheimintie | | 番地 | 34 | 34 | | 市区町村 | Helsinki | Helsinki | | 郵便番号 | 00100 | 00100 | | 電話番号 | +358401234567 | +358401234568 | #### フランス | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 10-07-1990 | 10-07-1990 | | 出生地 | パリ | パリ | | 名 | テスト | テスト | | 姓 | Person-fr | Person-fr | | メールアドレス | customer@email.fr | customer+denied@email.fr | | 町名・番地 | rue La Fayette | rue La Fayette | | 番地 | 33 | 33 | | 市区町村 | パリ | パリ | | 郵便番号 | 75009 | 75009 | | 電話番号 | +33689854321 | +33687984322 | #### ドイツ | | 承認済み | 拒否済み | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | 模擬 | テスト | | 姓 | 模擬 | Person-de | | メールアドレス | customer@email.de | customer+denied@email.de | | 町名・番地 | Neue Schönhauser Str. | Neue Schönhauser Str. | | 番地 | 2 | 2 | | 市 | Berlin | Berlin | | 郵便番号 | 10178 | 10178 | | 電話番号 | +49017614284340 | +49017610927312 | #### ギリシャ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 納税者番号 | 090000045 | 090000045 | | 生年月日 | 01-01-1960 | 11-11-1970 | | 名 | テスト | テスト | | 姓 | Person-gr | Test-gr | | メールアドレス | customer@email.gr | customer+denied@email.gr | | 町名・番地 | Kephisias | Baralo | | 番地 | 37 | 56 | | 郵便番号 | 151 23 | 123 67 | | 市区町村 | Athina | Athina | | 電話番号 | +306945553624 | +306945553625 | #### アイルランド | | 承認済み | 拒否 | | -------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ie | Person-ie | | メール | customer@email.ie | customer+denied@email.ie | | 町名・番地 | King Street South | King Street South | | 番地 | 30 | 30 | | 市区町村 | ダブリン | ダブリン | | EIR Code | D02 C838 | D02 C838 | | 電話番号 | +353855351400 | +353855351401 | #### イタリア | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 01-01-1980 | | 名 | テスト | テスト | | 姓 | Person-it | Person-it | | メールアドレス | customer@email.it | customer+denied@email.it | | 納税番号 | RSSBNC80A41H501B | RSSBNC80A41H501B | | 町名・番地 | Via Enrico Fermi | Via Enrico Fermi | | 番地 | 150 | 150 | | 市区町村 | Roma | Roma | | 郵便番号 | 00146 | 00146 | | 電話番号 | +393339741231 | +393312232389 | #### オランダ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nl | Person-nl | | メールアドレス | customer@email.nl | customer+denied@email.nl | | 町名・番地 | Osdorpplein | Osdorpplein | | 番地 | 137 | 137 | | 市区町村 | Amsterdam | Amsterdam | | 郵便番号 | 1068 SR | 1068 SR | | 電話番号 | +31689124321 | +31632167678 | #### ニュージーランド | | 承認 | 拒否 | | ------- | ------------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nz | Person-nz | | 町名・番地 | Mount Wellington Highway | Mount Wellington Highway | | 番地等 | 286 | 286 | | 郵便番号 | 6011 | 6011 | | 市区町村 | Auckland | Wellington | | 電話番号 | +6427555290 | +642993007712 | | メールアドレス | customer@email.nz | customer+denied@email.nz | #### ノルウェー | | 承認済み | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 01-08-1970 | 01-08-1970 | | 名 | Jane | テスト | | 姓 | テスト | Person-no | | メールアドレス | customer@email.no | customer+denied@email.no | | 個人番号 | NO1087000571 | NO1087000148 | | 町名・番地 | Edvard Munchs Plass | Sæffleberggate | | 番地 | 1 | 56 | | 市区町村 | Oslo | Oslo | | 郵便番号 | 0194 | 0563 | | 電話番号 | +4740123456 | +4740123457 | #### ポーランド | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 05-05-1967 | 05-05-1967 | | 名 | テスト | テスト | | 姓 | Person-pl | Person-pl | | 町名・番地 | Ul. Górczewska | Ul. Górczewska | | 番地等 | 124 | 124 | | 郵便番号 | 01-460 | 01-460 | | 市区町村 | Warszawa | Warszawa | | 電話番号 | +48795222223 | +48795223325 | | メールアドレス | customer@email.pl | customer+denied@email.pl | #### ポルトガル | | 承認 | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-pt | Person-pt | | 町名・番地 | Avenida Dom João II | Avenida Dom João II | | 番地等 | 40 | 40 | | 郵便番号 | 1990-094 | 1990-094 | | 市区町村 | Lisboa | Lisboa | | 電話番号 | +351935556731 | +351915593837 | | メールアドレス | customer@email.pt | customer+denied@email.pt | #### ルーマニア | | 承認されました | 拒否 | | ------------ | ----------------- | ------------------------ | | 生年月日 | 1970 年 12 月 25 日 | 1970 年 12 月 25 日 | | 名 | テスト | テスト | | 姓 | Person-ro | Person-ro | | メール | customer@email.ro | customer+denied@email.ro | | 町名・番地 | Drumul Taberei | Drumul Taberei | | 番地 | 35 | 35 | | 市区町村 | București | București | | セクター | Sectorul 6 | Sectorul 6 | | 郵便番号 | 061357 | 061357 | | 電話 | +40741209876 | +40707127444 | | 個人識別番号 (CNP) | 1701225193558 | | #### スペイン | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | DNI/NIE | 99999999R | 99999999R | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-es | Person-es | | メールアドレス | customer@email.es | customer+denied@email.es | | 町名・番地 | C. de Atocha | C. de Atocha | | 番地 | 27 | 27 | | 市区町村 | Madrid | Madrid | | 郵便番号 | 28012 | 28012 | | 電話番号 | +34672563009 | +34682425101 | #### スウェーデン | | 承認済み | 拒否 | | ------- | ----------------------- | ------------------------ | | 生年月日 | 21-03-1941 | 28-10-1941 | | 名 | Alice | テスト | | 姓 | テスト | Person-se | | メールアドレス | customer@email.se | customer+denied@email.se | | 町名・番地 | Södra Blasieholmshamnen | Karlaplan | | 番地 | 2 | 3 | | 市区町村 | Stockholm | Stockholm | | 郵便番号 | 11 148 | 11 460 | | 電話番号 | +46701740615 | +46701740620 | #### スイス | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1990 | 01-01-2000 | | 名 | 受付済み | 顧客 | | 姓 | Person-ch | Person-ch | | 町名・番地 | Augustinergasse | Bahnhofstrasse | | 番地等 | 2 | 77 | | 郵便番号 | 4051 | 8001 | | 市区町村 | Basel | Zürich | | 電話番号 | +41758680000 | +41758680001 | | メールアドレス | customer@email.ch | customer+denied@email.ch | #### イギリス | | 承認済み | 拒否 | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-uk | Person-uk | | メールアドレス | customer@email.uk | customer+denied@email.uk | | 町名・番地 | New Burlington Street | New Burlington Street | | 番地 | 10 | 10 | | アパート | Apt 214 | Apt 214 | | 郵便番号 | W1S 3BE | W1S 3BE | | 市区町村 | London | London | | 電話番号 | +447755564318 | +447355505530 | #### アメリカ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 07-10-1970 | 07-10-1970 | | 名 | テスト | テスト | | 姓 | Person-us | Person-us | | メールアドレス | customer@email.us | customer+denied@email.us | | 町名・番地 | Amsterdam Ave | Amsterdam Ave | | 番地 | 509 | 509 | | 市区町村 | New York | New York | | 州 | New York | New York | | 郵便番号 | 10024-3941 | 10024-3941 | | 電話番号 | +13106683312 | +13106354386 | 実働環境のテストのために、現地通貨の金額 `3500` を使用して、融資以外のすべての Klarna 支払いオプションをテストできます。たとえば、イタリアでの「3 回払い」をテストする場合は、35.00 EUR の取引を使用できます。 ### 2 段階認証 6 桁の数字であれば、2 段階認証コードとして有効です。`999999` を使用すると、認証は失敗します。 ### 返済方法 Klarna のフロー内では、以下のテスト値を使用し、さまざまな返済方法を試すことができます。 | タイプ | 値 | | -------- | ---------------------------------------------------------- | | 口座引き落とし | DE11520513735120710131 | | 銀行振込 | デモの銀行 | | クレジットカード | - 番号: 4111 1111 1111 1111 - CVV: 123 - 有効期限: 任意の将来日付 | | デビットカード | - カード番号:4012 8888 8888 1881 - CVV: 123 - 有効期限: 任意の将来日付 | # iOS > This is a iOS for when payment-ui is mobile and platform is ios. View the full page at https://docs.stripe.com/payments/klarna/accept-a-payment?payment-ui=mobile&platform=ios. アプリで Klarna を受け付けるには、顧客が支払いを認証するための Webview を表示します。その後、顧客はアプリに戻り、お客様は支払いが成功したか失敗したかをすぐに*確認* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects)できます。 ## Stripe を設定する [サーバ側] [クライアント側] まず、Stripe アカウントが必要です。[今すぐ登録](https://dashboard.stripe.com/register)してください。 ### サーバ側 この組み込みには、サーバ上に Stripe API と通信するエンドポイントが必要です。サーバから Stripe API にアクセスするには、Stripe の公式ライブラリを使用します。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ### クライアント側 [Stripe iOS SDK](https://github.com/stripe/stripe-ios) はオープンソースです。[詳細なドキュメントが提供されており](https://stripe.dev/stripe-ios/index.html)、iOS 13 以降をサポートするアプリと互換性があります。 #### Swift Package Manager SDK をインストールするには、以下のステップに従います。 1. Xcode で、**File (ファイル)** > **Add Package Dependencies… (パッケージ依存関係を追加)** を選択し、リポジトリー URL として `https://github.com/stripe/stripe-ios-spm` を入力します。 1. [リリースページ](https://github.com/stripe/stripe-ios/releases)から最新のバージョン番号を選択します。 1. **StripePaymentsUI** 製品を[アプリのターゲット](https://developer.apple.com/documentation/swift_packages/adding_package_dependencies_to_your_app)に追加します。 #### CocoaPods 1. まだインストールしていない場合は、[CocoaPods](https://guides.cocoapods.org/using/getting-started.html) の最新バージョンをインストールします。 1. 既存の [Podfile](https://guides.cocoapods.org/syntax/podfile.html) がない場合は、以下のコマンドを実行して作成します。 ```bash pod init ``` 1. この行を `Podfile` に追加します。 ```podfile pod 'StripePaymentsUI' ``` 1. 以下のコマンドを実行します。 ```bash pod install ``` 1. これ以降は、Xcode でプロジェクトを開く際に、`.xcodeproj` ファイルではなく、必ず `.xcworkspace` ファイルを使用するということを忘れないでください。 1. 今後、SDK の最新バージョンに更新するには、以下を実行します。 ```bash pod update StripePaymentsUI ``` #### Carthage 1. まだインストールしていない場合は、[Carthage](https://github.com/Carthage/Carthage#installing-carthage) の最新バージョンをインストールします。 1. この行を `Cartfile` に追加します。 ```cartfile github "stripe/stripe-ios" ``` 1. [Carthage のインストール手順](https://github.com/Carthage/Carthage#if-youre-building-for-ios-tvos-or-watchos)に従います。必ず、[こちら](https://github.com/stripe/stripe-ios/tree/master/StripePaymentsUI/README.md#manual-linking)にリストされている必要なフレームワークのすべてを埋め込んでください。 1. 今後、SDK の最新バージョンに更新するには、以下のコマンドを実行します。 ```bash carthage update stripe-ios --platform ios ``` #### 手動のフレームワーク 1. Stripe の [GitHub リリースページ](https://github.com/stripe/stripe-ios/releases/latest)に移動して、**Stripe.xcframework.zip** をダウンロードして解凍します。 1. **StripePaymentsUI.xcframework** を、Xcode プロジェクトの **General (一般) ** 設定の **Embedded Binaries (埋め込みバイナリー)** セクションにドラッグします。**Copy items if needed (必要に応じてアイテムをコピーする)** を必ず選択してください。 1. [こちら](https://github.com/stripe/stripe-ios/tree/master/StripePaymentsUI/README.md#manual-linking)にリストされている必要なフレームワークのすべてに対して、ステップ 2 を繰り返します。 1. 今後、Stripe の SDK の最新バージョンに更新するには、ステップ 1 から 3 を繰り返します。 > SDK の最新リリースおよび過去バージョンの詳細については、GitHub の [Releases (リリース)](https://github.com/stripe/stripe-ios/releases) ページをご覧ください。リポジトリの[リリースをウォッチ](https://help.github.com/en/articles/watching-and-unwatching-releases-for-a-repository#watching-releases-for-a-repository)して、新しいリリースの公開時に通知を受け取ることも可能です。 アプリの起動時に Stripe [公開可能キー](https://dashboard.stripe.com/test/apikeys)を使用して SDK を設定します。これにより、アプリが Stripe API にリクエストを送信できるようになります。 #### Swift ```swift import UIKitimportStripePaymentsUI @main class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {StripeAPI.defaultPublishableKey = "<>" // do any other necessary launch configuration return true } } ``` > テストおよび開発時には[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。 ## PaymentIntent を作成する [サーバー側] [クライアント側] [PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) は、顧客から支払いを回収する意図を表すオブジェクトであり、支払いプロセスのライフサイクルをステージごとに追跡します。 ### サーバー側 まず、サーバーで `PaymentIntent` を作成し、回収する金額と通貨を指定します。[Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) を使用した組み込みをすでにお持ちの場合には、`klarna` を `PaymentIntent` の[決済手段タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)のリストに追加します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur ``` ### クライアント側 返される PaymentIntent には *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。これは、PaymentIntent オブジェクト全体を渡すことなく安全に決済を完了するために、クライアント側で使用されます。クライアント側で、サーバーに PaymentIntent をリクエストし、その client secret を保存します。 #### Swift ```swift import UIKit import StripePaymentsUI class CheckoutViewController: UIViewController { var paymentIntentClientSecret: String? func startCheckout() { // Request a PaymentIntent from your server and store its client secret } }} ``` ## Stripe に支払いを送信する [クライアント側] ステップ 2 で作成した PaymentIntent から client secret を取得し、[STPPaymentHandler confirmPayment:](https://stripe.dev/stripe-ios/stripe-payments/Classes/STPPaymentHandler.html#/c:@M@StripePayments@objc\(cs\)STPPaymentHandler\(im\)confirmPayment:withAuthenticationContext:completion:) メソッドを呼び出します。これにより WebView が表示され、顧客はここで支払いを完了します。それによって支払い結果を含む完了ブロックの呼び出しが開始されます。 #### Swift ```swift let paymentIntentParams = STPPaymentIntentParams(clientSecret: paymentIntentClientSecret) paymentIntentParams.paymentMethodParams = klarnaParams paymentIntentParams.shipping = shippingDetails STPPaymentHandler.shared().confirmPayment(paymentIntentParams, with: self) { (handlerStatus, paymentIntent, error) in switch handlerStatus { case .succeeded: // Payment succeeded case .canceled: // Payment was canceled case .failed: // Payment failed @unknown default: fatalError() } } ``` ## Klarna の組み込みをテストする > Klarna はセッションの追跡に クッキーを使用します。さまざまな顧客の所在地をテストするには、前のセッションで Klarna サンドボックスからログアウトし、関連するトリガーを使用します。 下記では、現在対応している顧客の国のテストデータを特別に選択しています。サンドボックスでは、Klarna は指定されたメールアドレスに基づいて取引を承認または拒否します。 #### オーストラリア | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 03-05-1994 | | 名 | テスト | John | | 姓 | Person-au | snow | | 町名・番地 | Wharf St | Silverwater Rd | | 番地等 | 4 | 1-5 | | 郵便番号 | 4877 | 2128 | | 市区町村 | Port Douglas | Silverwater | | 地域 | QLD | NSW | | 電話番号 | +61473752244 | +61473763254 | | メールアドレス | customer@email.au | customer+denied@email.au | #### オーストリア | | 承認済み | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-at | Person-at | | メールアドレス | customer@email.at | customer+denied@email.at | | 町名・番地 | Mariahilfer Straße | Mariahilfer Straße | | 番地 | 47 | 47 | | 市区町村 | Wien | Wien | | 郵便番号 | 1060 | 1060 | | 電話番号 | +4306762600456 | +4306762600745 | #### ベルギー | | 承認済み | 拒否済み | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-be | Person-be | | メールアドレス | customer@email.be | customer+denied@email.be | | 町名・番地 | Grote Markt | Grote Markt | | 番地 | 1 | 1 | | 市 | Brussel | Brussel | | 郵便番号 | 1000 | 1000 | | 電話番号 | +32485121291 | +32485212123 | #### カナダ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ca | Person-ca | | 町名・番地 | 2693 Byron Rd | 2693 Byron Rd | | 郵便番号 | V7H 1L9 | V7H 1L9 | | 市区町村 | North Vancouver | North Vancouver | | 地域 | BC | BC | | 電話番号 | +15197438620 | +15197308624 | | メールアドレス | customer@email.ca | customer+denied@email.ca | #### チェコ | | 承認 | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 01-01-1970 | 27-06-1992 | | 名 | テスト | テスト | | 姓 | Person-cz | Person-cz | | メールアドレス | customer@email.cz | customer+denied@email.cz | | 町名・番地 | Zazvorkova 1480/11 | Zázvorkova 1480/11 | | 郵便番号 | 155 00 | 155 00 | | 市区町村 | Praha | PRAHA 13 | | 電話番号 | +420771613715 | +420771623691 | #### デンマーク | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-dk | Person-dk | | メールアドレス | customer@email.dk | customer+denied@email.dk | | 町名・番地 | Dantes Plads | Nygårdsvej | | 番地 | 7 | 65 | | 市区町村 | København Ø | København Ø | | 郵便番号 | 1556 | 2100 | | 電話番号 | +4542555628 | +4552555348 | #### フィンランド | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1999 | 01-01-1999 | | 名 | テスト | Person FI | | 姓 | Person-fi | テスト | | メールアドレス | customer@email.fi | customer+denied@email.fi | | 町名・番地 | Mannerheimintie | Mannerheimintie | | 番地 | 34 | 34 | | 市区町村 | Helsinki | Helsinki | | 郵便番号 | 00100 | 00100 | | 電話番号 | +358401234567 | +358401234568 | #### フランス | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 10-07-1990 | 10-07-1990 | | 出生地 | パリ | パリ | | 名 | テスト | テスト | | 姓 | Person-fr | Person-fr | | メールアドレス | customer@email.fr | customer+denied@email.fr | | 町名・番地 | rue La Fayette | rue La Fayette | | 番地 | 33 | 33 | | 市区町村 | パリ | パリ | | 郵便番号 | 75009 | 75009 | | 電話番号 | +33689854321 | +33687984322 | #### ドイツ | | 承認済み | 拒否済み | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | 模擬 | テスト | | 姓 | 模擬 | Person-de | | メールアドレス | customer@email.de | customer+denied@email.de | | 町名・番地 | Neue Schönhauser Str. | Neue Schönhauser Str. | | 番地 | 2 | 2 | | 市 | Berlin | Berlin | | 郵便番号 | 10178 | 10178 | | 電話番号 | +49017614284340 | +49017610927312 | #### ギリシャ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 納税者番号 | 090000045 | 090000045 | | 生年月日 | 01-01-1960 | 11-11-1970 | | 名 | テスト | テスト | | 姓 | Person-gr | Test-gr | | メールアドレス | customer@email.gr | customer+denied@email.gr | | 町名・番地 | Kephisias | Baralo | | 番地 | 37 | 56 | | 郵便番号 | 151 23 | 123 67 | | 市区町村 | Athina | Athina | | 電話番号 | +306945553624 | +306945553625 | #### アイルランド | | 承認済み | 拒否 | | -------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ie | Person-ie | | メール | customer@email.ie | customer+denied@email.ie | | 町名・番地 | King Street South | King Street South | | 番地 | 30 | 30 | | 市区町村 | ダブリン | ダブリン | | EIR Code | D02 C838 | D02 C838 | | 電話番号 | +353855351400 | +353855351401 | #### イタリア | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 01-01-1980 | | 名 | テスト | テスト | | 姓 | Person-it | Person-it | | メールアドレス | customer@email.it | customer+denied@email.it | | 納税番号 | RSSBNC80A41H501B | RSSBNC80A41H501B | | 町名・番地 | Via Enrico Fermi | Via Enrico Fermi | | 番地 | 150 | 150 | | 市区町村 | Roma | Roma | | 郵便番号 | 00146 | 00146 | | 電話番号 | +393339741231 | +393312232389 | #### オランダ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nl | Person-nl | | メールアドレス | customer@email.nl | customer+denied@email.nl | | 町名・番地 | Osdorpplein | Osdorpplein | | 番地 | 137 | 137 | | 市区町村 | Amsterdam | Amsterdam | | 郵便番号 | 1068 SR | 1068 SR | | 電話番号 | +31689124321 | +31632167678 | #### ニュージーランド | | 承認 | 拒否 | | ------- | ------------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nz | Person-nz | | 町名・番地 | Mount Wellington Highway | Mount Wellington Highway | | 番地等 | 286 | 286 | | 郵便番号 | 6011 | 6011 | | 市区町村 | Auckland | Wellington | | 電話番号 | +6427555290 | +642993007712 | | メールアドレス | customer@email.nz | customer+denied@email.nz | #### ノルウェー | | 承認済み | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 01-08-1970 | 01-08-1970 | | 名 | Jane | テスト | | 姓 | テスト | Person-no | | メールアドレス | customer@email.no | customer+denied@email.no | | 個人番号 | NO1087000571 | NO1087000148 | | 町名・番地 | Edvard Munchs Plass | Sæffleberggate | | 番地 | 1 | 56 | | 市区町村 | Oslo | Oslo | | 郵便番号 | 0194 | 0563 | | 電話番号 | +4740123456 | +4740123457 | #### ポーランド | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 05-05-1967 | 05-05-1967 | | 名 | テスト | テスト | | 姓 | Person-pl | Person-pl | | 町名・番地 | Ul. Górczewska | Ul. Górczewska | | 番地等 | 124 | 124 | | 郵便番号 | 01-460 | 01-460 | | 市区町村 | Warszawa | Warszawa | | 電話番号 | +48795222223 | +48795223325 | | メールアドレス | customer@email.pl | customer+denied@email.pl | #### ポルトガル | | 承認 | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-pt | Person-pt | | 町名・番地 | Avenida Dom João II | Avenida Dom João II | | 番地等 | 40 | 40 | | 郵便番号 | 1990-094 | 1990-094 | | 市区町村 | Lisboa | Lisboa | | 電話番号 | +351935556731 | +351915593837 | | メールアドレス | customer@email.pt | customer+denied@email.pt | #### ルーマニア | | 承認されました | 拒否 | | ------------ | ----------------- | ------------------------ | | 生年月日 | 1970 年 12 月 25 日 | 1970 年 12 月 25 日 | | 名 | テスト | テスト | | 姓 | Person-ro | Person-ro | | メール | customer@email.ro | customer+denied@email.ro | | 町名・番地 | Drumul Taberei | Drumul Taberei | | 番地 | 35 | 35 | | 市区町村 | București | București | | セクター | Sectorul 6 | Sectorul 6 | | 郵便番号 | 061357 | 061357 | | 電話 | +40741209876 | +40707127444 | | 個人識別番号 (CNP) | 1701225193558 | | #### スペイン | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | DNI/NIE | 99999999R | 99999999R | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-es | Person-es | | メールアドレス | customer@email.es | customer+denied@email.es | | 町名・番地 | C. de Atocha | C. de Atocha | | 番地 | 27 | 27 | | 市区町村 | Madrid | Madrid | | 郵便番号 | 28012 | 28012 | | 電話番号 | +34672563009 | +34682425101 | #### スウェーデン | | 承認済み | 拒否 | | ------- | ----------------------- | ------------------------ | | 生年月日 | 21-03-1941 | 28-10-1941 | | 名 | Alice | テスト | | 姓 | テスト | Person-se | | メールアドレス | customer@email.se | customer+denied@email.se | | 町名・番地 | Södra Blasieholmshamnen | Karlaplan | | 番地 | 2 | 3 | | 市区町村 | Stockholm | Stockholm | | 郵便番号 | 11 148 | 11 460 | | 電話番号 | +46701740615 | +46701740620 | #### スイス | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1990 | 01-01-2000 | | 名 | 受付済み | 顧客 | | 姓 | Person-ch | Person-ch | | 町名・番地 | Augustinergasse | Bahnhofstrasse | | 番地等 | 2 | 77 | | 郵便番号 | 4051 | 8001 | | 市区町村 | Basel | Zürich | | 電話番号 | +41758680000 | +41758680001 | | メールアドレス | customer@email.ch | customer+denied@email.ch | #### イギリス | | 承認済み | 拒否 | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-uk | Person-uk | | メールアドレス | customer@email.uk | customer+denied@email.uk | | 町名・番地 | New Burlington Street | New Burlington Street | | 番地 | 10 | 10 | | アパート | Apt 214 | Apt 214 | | 郵便番号 | W1S 3BE | W1S 3BE | | 市区町村 | London | London | | 電話番号 | +447755564318 | +447355505530 | #### アメリカ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 07-10-1970 | 07-10-1970 | | 名 | テスト | テスト | | 姓 | Person-us | Person-us | | メールアドレス | customer@email.us | customer+denied@email.us | | 町名・番地 | Amsterdam Ave | Amsterdam Ave | | 番地 | 509 | 509 | | 市区町村 | New York | New York | | 州 | New York | New York | | 郵便番号 | 10024-3941 | 10024-3941 | | 電話番号 | +13106683312 | +13106354386 | ### 2 段階認証 6 桁の数字であれば、2 段階認証コードとして有効です。`999999` を使用すると、認証は失敗します。 ### 返済方法 Klarna のフロー内では、以下のテスト値を使用し、さまざまな返済方法を試すことができます。 | タイプ | 値 | | -------- | ---------------------------------------------------------- | | 口座引き落とし | DE11520513735120710131 | | 銀行振込 | デモの銀行 | | クレジットカード | - 番号: 4111 1111 1111 1111 - CVV: 123 - 有効期限: 任意の将来日付 | | デビットカード | - カード番号:4012 8888 8888 1881 - CVV: 123 - 有効期限: 任意の将来日付 | ## Optional: オーソリとキャプチャーの分離 Klarna は[オーソリとキャプチャの分離](https://docs.stripe.com/payments/place-a-hold-on-a-payment-method.md)に対応しています。支払いから顧客への商品の配送までに遅延が生じた場合、まず支払いをオーソリし、後でキャプチャーします。キャプチャーされた時点で、Klarna は顧客に明細書を送り、必要となる以降の支払いの期日を作成します。**オーソリされた Klarna の支払いは、オーソリから 28 日以内にキャプチャーする必要があります** 。キャンセルされない場合、オーソリは自動的にキャンセルされ、支払いをキャプチャーできなくなります。 1. オーソリのみ行うように Stripe に指示する オーソリとキャプチャーを分離することを指定するには、PaymentIntent の作成時に、[capture_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-capture_method) を `manual` に設定します。このパラメーターは、顧客の Klarna アカウントの金額のみをオーソリするよう Stripe に指示します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur \ -d capture_method=manual ``` 1. 売上をキャプチャーする 承認が完了すると、PaymentIntent の [ステータス](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-status)は `requires_capture` に移行します。承認済みの売上をキャプチャーするには、PaymentIntent の [キャプチャー](https://docs.stripe.com/api/payment_intents/capture.md)リクエストを作成します。デフォルトでは承認済みの総額がキャプチャーされます。これを超える金額をキャプチャーすることはできませんが、これより少ない金額をキャプチャーすることは可能です。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}}/capture \ -u "<>:" \ -d amount_to_capture=750 ``` 1. (任意)オーソリをキャンセルする Klarna は、Klarna 内での顧客の総計購買力に対して、承認された決済件数を計算します。このため、フルフィルメントを行えない承認済みの決済 (商品を配送できないなど) は、それが明らかになり次第、早急にキャンセルする必要があります。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}}/cancel \ -u "<>:" \ -d cancellation_reason=abandoned ``` ## Optional: 支払い後のイベントを処理する 支払いが完了すると、Stripe は [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) イベントを送信します。ダッシュボード、カスタム *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests)、またはパートナーソリューションを使用してこれらのイベントを受信し、また、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行します。 クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアント側では、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了したりする可能性があります。また、悪意を持つクライアントがレスポンスを不正操作する恐れもあります。非同期型のイベントをリッスンするよう構築済みのシステムを設定することで、これ以降はより多くの決済手段を簡単に受け付けられるようになります。[サポートされているすべての決済手段の違い](https://stripe.com/payments/payment-methods-guide)をご確認ください。 - **ダッシュボードでイベントを手動で処理する** ダッシュボードを使用して、テスト決済を[ダッシュボードで表示](https://dashboard.stripe.com/test/payments)したり、メール領収書を送信したり、入金を処理したり、失敗した決済を再試行したりできます。 - **Custom Webhook を構築する** [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI. - **構築済みアプリを導入する** パートナーアプリケーションを統合することで、[自動化](https://stripe.partners/?f_category=automation)や[マーケティング/セールス](https://stripe.partners/?f_category=marketing-and-sales)などの一般的なビジネスイベントを処理します。 ## Optional: Klarna 支払いページをカスタマイズする - **Klarna フォームを事前入力する** 顧客が延べ払いオプションを使用して Klarna に決済することを選択すると (後払い、分割払い、融資など)、Klarna は、リスク評価と承認のために十分な情報を収集します。情報の種類は、顧客の国によって異なります。ほとんどのヨーロッパの国では、完全な請求先住所と生年月日です。この情報は API を通じて渡すことができ、顧客がページに到着する前にフォームが事前入力されます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur \ -d confirm=true \ --data-urlencode "return_url=https://example.com/checkout/complete" \ -d "payment_method_data[type]=klarna" \ --data-urlencode "payment_method_data[billing_details][email]=customer@example.com" \ -d "payment_method_data[billing_details][name]=Jenny Rosen" \ --data-urlencode "payment_method_data[billing_details][phone]=+4915142321555" \ -d "payment_method_data[billing_details][address][line1]=Alexanderplatz 1" \ -d "payment_method_data[billing_details][address][city]=Berlin" \ -d "payment_method_data[billing_details][address][postal_code]=10551" \ -d "payment_method_data[billing_details][address][country]=DE" \ -d "payment_method_data[klarna][dob][day]=10" \ -d "payment_method_data[klarna][dob][month]=10" \ -d "payment_method_data[klarna][dob][year]=1990" ``` ![API からの請求詳細が事前入力され、英語で表示されるようにカスタマイズされた Klarna の支払いページのスクリーンショット](https://b.stripecdn.com/docs-statics-srv/assets/klarna-kpp-prefilled-customized.75932cc9aa3223960aa2fcf769c1ce62.png) Klarna の支払いページは、API からの請求書詳細が事前入力され、カスタマイズされてドイツの顧客に英語で表示されます。 ## Optional: PaymentIntent にラインアイテムを追加する > #### Klarna との統合項目 > > Klarna を導入する際に承認率を最適化するには、`line_items` データを含めて買い物客のカートの中身を表します。先行提供版については、[支払い項目](https://docs.stripe.com/payments/payment-line-items.md)をご覧ください。 ## 失敗した支払い Klarna は、取引を受け付けるか拒否するかを決定する際に複数の要因を考慮します (買い手が Klarna を使用している期間、顧客が返済する必要のある未払い額、現在の注文の金額など)。 顧客が後払いを選択すると、Klarna は取引を受け付ける前にリスク評価を行います。Klarna は、リスク評価の結果が良好でなかったり、取引金額が大きかったり、顧客に多額の未払いの負債があったりすると、取引を拒否することがあります。そのため、決済フローに `card` などの他の支払いオプションを提示することをお勧めします。このような場合、[PaymentMethod](https://docs.stripe.com/api/payment_methods/object.md) は解除され、[PaymentInten](https://docs.stripe.com/api/payment_intents/object.md)オブジェクトのステータスは自動的に `requires_payment_method` に変わります。 顧客は、Klarna のサイトにリダイレクトされてから 48 時間以内に決済を完了する必要があります。48 時間経過しても対応しなかった場合、[PaymentMethod](https://docs.stripe.com/api/payment_methods/object.md) の関連付けが解除され、[PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) オブジェクトのステータスは自動的に `requires_action` から `requires_payment_method` に移行します。 このようなケースでは、決済フローに表示される別の支払いオプションで再試行するように顧客に通知します。 ### Klarna のレート制限 Klarna への API リクエストには、Stripe の [API 全体のレート制限](https://docs.stripe.com/rate-limits.md) を超える追加のレート制限が適用されます。これらの制限は、行う API リクエストの形状によって異なる場合があります。一般に、毎秒 50 を超えるリクエストを行うと、HTTP ステータスコード `400` または `402` の応答の形式でレート制限が表示されることがあります。使用量がこれらのレベルに達するのではないかとご心配な場合は、Klarna がケースバイケースでこれらの制限を増やすことができる可能性がありますので、Stripe まで[お問い合わせください](https://support.stripe.com)。 ### エラーメッセージ Klarna 支払いが失敗すると、通常、以下のエラーコードのいずれかが返されます。これらのコードは、[last_payment_error](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-last_payment_error) API オブジェクトに表示されます。 > `2023-08-16` API バージョンより前は、すべての Klarna エラーが [payment_intent_authentication_failure](https://docs.stripe.com/error-codes.md#payment_intent_authentication_failure) として報告されていました。API バージョンが最新であることを確認して、以下のエラー詳細をご覧ください。 | エラーコード | 説明 | | ----------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | | [payment_method_customer_decline](https://docs.stripe.com/error-codes.md#payment-method-customer-decline) | 顧客が Klarna のページで決済をキャンセルしました | | [payment_method_provider_decline](https://docs.stripe.com/error-codes.md#payment-method-provider-decline) | Klarna が顧客の支払いを拒否しました | | [payment_intent_payment_attempt_expired](https://docs.stripe.com/error-codes.md#payment-intent-payment-attempt-expired) | 顧客が Klarna のページで購入を完了しないまま、支払いセッションの有効期限が切れました | | [payment_method_not_available](https://docs.stripe.com/error-codes.md#payment-method-not-available) | Klarna を使用しようとしたときに予期しないエラーが発生しました | # Android > This is a Android for when payment-ui is mobile and platform is android. View the full page at https://docs.stripe.com/payments/klarna/accept-a-payment?payment-ui=mobile&platform=android. アプリで Klarna を受け付けるには、顧客が支払いを認証するための Webview を表示します。その後、顧客はアプリに戻り、お客様は支払いが成功したか失敗したかをすぐに*確認* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects)できます。 ## Stripe を設定する [サーバ側] [クライアント側] まず、Stripe アカウントが必要です。[今すぐ登録](https://dashboard.stripe.com/register)してください。 ### サーバ側 この組み込みには、サーバ上に Stripe API と通信するエンドポイントが必要です。サーバから Stripe API にアクセスするには、Stripe の公式ライブラリを使用します。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ### クライアント側 [Stripe Android SDK](https://github.com/stripe/stripe-android) はオープンソースであり、[詳細なドキュメントが提供されています](https://stripe.dev/stripe-android/)。 SDK をインストールするには、[app/build.gradle](https://developer.android.com/studio/build/dependencies) ファイルの `dependencies` ブロックに `stripe-android` を追加します。 #### Kotlin ```kotlin plugins { id("com.android.application") } android { ... } dependencies { // ... // Stripe Android SDK implementation("com.stripe:stripe-android:23.2.0") // Include the financial connections SDK to support US bank account as a payment method implementation("com.stripe:financial-connections:23.2.0") } ``` > SDK の最新リリースおよび過去バージョンの詳細については、GitHub の [Releases](https://github.com/stripe/stripe-android/releases) ページをご覧ください。新しいリリースの公開時に通知を受け取るには、[リポジトリのリリースを確認](https://docs.github.com/en/github/managing-subscriptions-and-notifications-on-github/configuring-notifications#configuring-your-watch-settings-for-an-individual-repository)してください。 Stripe の[公開可能キー](https://dashboard.stripe.com/apikeys)を使用して SDK を設定し、 `Application` サブクラスなどで、Stripe API へのリクエストを実行できるようにします。 #### Kotlin ```kotlin import com.stripe.android.PaymentConfiguration class MyApp : Application() { override fun onCreate() { super.onCreate() PaymentConfiguration.init( applicationContext, "<>" ) } } ``` > テストおよび開発時には[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。 Stripe サンプルでは、サーバへの HTTP リクエストの作成に、[OkHttp](https://github.com/square/okhttp) および [GSON](https://github.com/google/gson) も使用します。 ## PaymentIntent を作成する [サーバー側] [クライアント側] [PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) は、顧客から支払いを回収する意図を表すオブジェクトであり、支払いプロセスのライフサイクルをステージごとに追跡します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur ``` ### クライアント側 返される PaymentIntent には *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。これは、PaymentIntent オブジェクト全体を渡すことなく安全に決済を完了するために、クライアント側で使用されます。クライアント側で、サーバーに PaymentIntent をリクエストし、その client secret を保存します。 #### Kotlin ```kotlin class KlarnaPaymentActivity: AppCompatActivity() { private lateinit var paymentIntentClientSecret: String override fun onCreate(savedInstanceState: Bundle?) { // ... startCheckout() } private fun startCheckout() { // Request a PaymentIntent from your server and store its client secret } } ``` ## Stripe に支払いを送信する [クライアント側] ステップ 2 で作成した PaymentIntent から Client Secret を取得し、[PaymentLauncher.confirm](https://stripe.dev/stripe-android/payments-core/com.stripe.android.payments.paymentlauncher/-payment-launcher/index.html#74063765%2FFunctions%2F-1622557690) メソッドを呼び出します。これにより、顧客が支払いを完了できるウェブビューが表示されます。その後、支払い結果とともに onActivityResult が呼び出されます。 #### Kotlin ```kotlin class KlarnaPaymentActivity : AppCompatActivity() { // ... private lateinit var paymentIntentClientSecret: String private val paymentLauncher: PaymentLauncher by lazy { val paymentConfiguration = PaymentConfiguration.getInstance(applicationContext) PaymentLauncher.Companion.create( this, paymentConfiguration.publishableKey, paymentConfiguration.stripeAccountId, ::onPaymentResult ) } private fun startCheckout() { // ... val confirmParams = ConfirmPaymentIntentParams .createWithPaymentMethodCreateParams( paymentMethodCreateParams = paymentMethodCreateParams, clientSecret = paymentIntentClientSecret, shipping = shippingDetails ) paymentLauncher.confirm(confirmParams) } private fun onPaymentResult(paymentResult: PaymentResult) { when (paymentResult) { is PaymentResult.Completed -> { // show success UI } is PaymentResult.Canceled -> { // handle cancel flow } is PaymentResult.Failed -> { // handle failures // (for example, the customer may need to choose a new payment // method) } } } } ``` ## Klarna の組み込みをテストする > Klarna はセッションの追跡に クッキーを使用します。さまざまな顧客の所在地をテストするには、前のセッションで Klarna サンドボックスからログアウトし、関連するトリガーを使用します。 下記では、現在対応している顧客の国のテストデータを特別に選択しています。サンドボックスでは、Klarna は指定されたメールアドレスに基づいて取引を承認または拒否します。 #### オーストラリア | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 03-05-1994 | | 名 | テスト | John | | 姓 | Person-au | snow | | 町名・番地 | Wharf St | Silverwater Rd | | 番地等 | 4 | 1-5 | | 郵便番号 | 4877 | 2128 | | 市区町村 | Port Douglas | Silverwater | | 地域 | QLD | NSW | | 電話番号 | +61473752244 | +61473763254 | | メールアドレス | customer@email.au | customer+denied@email.au | #### オーストリア | | 承認済み | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-at | Person-at | | メールアドレス | customer@email.at | customer+denied@email.at | | 町名・番地 | Mariahilfer Straße | Mariahilfer Straße | | 番地 | 47 | 47 | | 市区町村 | Wien | Wien | | 郵便番号 | 1060 | 1060 | | 電話番号 | +4306762600456 | +4306762600745 | #### ベルギー | | 承認済み | 拒否済み | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-be | Person-be | | メールアドレス | customer@email.be | customer+denied@email.be | | 町名・番地 | Grote Markt | Grote Markt | | 番地 | 1 | 1 | | 市 | Brussel | Brussel | | 郵便番号 | 1000 | 1000 | | 電話番号 | +32485121291 | +32485212123 | #### カナダ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ca | Person-ca | | 町名・番地 | 2693 Byron Rd | 2693 Byron Rd | | 郵便番号 | V7H 1L9 | V7H 1L9 | | 市区町村 | North Vancouver | North Vancouver | | 地域 | BC | BC | | 電話番号 | +15197438620 | +15197308624 | | メールアドレス | customer@email.ca | customer+denied@email.ca | #### チェコ | | 承認 | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 01-01-1970 | 27-06-1992 | | 名 | テスト | テスト | | 姓 | Person-cz | Person-cz | | メールアドレス | customer@email.cz | customer+denied@email.cz | | 町名・番地 | Zazvorkova 1480/11 | Zázvorkova 1480/11 | | 郵便番号 | 155 00 | 155 00 | | 市区町村 | Praha | PRAHA 13 | | 電話番号 | +420771613715 | +420771623691 | #### デンマーク | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-dk | Person-dk | | メールアドレス | customer@email.dk | customer+denied@email.dk | | 町名・番地 | Dantes Plads | Nygårdsvej | | 番地 | 7 | 65 | | 市区町村 | København Ø | København Ø | | 郵便番号 | 1556 | 2100 | | 電話番号 | +4542555628 | +4552555348 | #### フィンランド | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1999 | 01-01-1999 | | 名 | テスト | Person FI | | 姓 | Person-fi | テスト | | メールアドレス | customer@email.fi | customer+denied@email.fi | | 町名・番地 | Mannerheimintie | Mannerheimintie | | 番地 | 34 | 34 | | 市区町村 | Helsinki | Helsinki | | 郵便番号 | 00100 | 00100 | | 電話番号 | +358401234567 | +358401234568 | #### フランス | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 10-07-1990 | 10-07-1990 | | 出生地 | パリ | パリ | | 名 | テスト | テスト | | 姓 | Person-fr | Person-fr | | メールアドレス | customer@email.fr | customer+denied@email.fr | | 町名・番地 | rue La Fayette | rue La Fayette | | 番地 | 33 | 33 | | 市区町村 | パリ | パリ | | 郵便番号 | 75009 | 75009 | | 電話番号 | +33689854321 | +33687984322 | #### ドイツ | | 承認済み | 拒否済み | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | 模擬 | テスト | | 姓 | 模擬 | Person-de | | メールアドレス | customer@email.de | customer+denied@email.de | | 町名・番地 | Neue Schönhauser Str. | Neue Schönhauser Str. | | 番地 | 2 | 2 | | 市 | Berlin | Berlin | | 郵便番号 | 10178 | 10178 | | 電話番号 | +49017614284340 | +49017610927312 | #### ギリシャ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 納税者番号 | 090000045 | 090000045 | | 生年月日 | 01-01-1960 | 11-11-1970 | | 名 | テスト | テスト | | 姓 | Person-gr | Test-gr | | メールアドレス | customer@email.gr | customer+denied@email.gr | | 町名・番地 | Kephisias | Baralo | | 番地 | 37 | 56 | | 郵便番号 | 151 23 | 123 67 | | 市区町村 | Athina | Athina | | 電話番号 | +306945553624 | +306945553625 | #### アイルランド | | 承認済み | 拒否 | | -------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ie | Person-ie | | メール | customer@email.ie | customer+denied@email.ie | | 町名・番地 | King Street South | King Street South | | 番地 | 30 | 30 | | 市区町村 | ダブリン | ダブリン | | EIR Code | D02 C838 | D02 C838 | | 電話番号 | +353855351400 | +353855351401 | #### イタリア | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 01-01-1980 | | 名 | テスト | テスト | | 姓 | Person-it | Person-it | | メールアドレス | customer@email.it | customer+denied@email.it | | 納税番号 | RSSBNC80A41H501B | RSSBNC80A41H501B | | 町名・番地 | Via Enrico Fermi | Via Enrico Fermi | | 番地 | 150 | 150 | | 市区町村 | Roma | Roma | | 郵便番号 | 00146 | 00146 | | 電話番号 | +393339741231 | +393312232389 | #### オランダ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nl | Person-nl | | メールアドレス | customer@email.nl | customer+denied@email.nl | | 町名・番地 | Osdorpplein | Osdorpplein | | 番地 | 137 | 137 | | 市区町村 | Amsterdam | Amsterdam | | 郵便番号 | 1068 SR | 1068 SR | | 電話番号 | +31689124321 | +31632167678 | #### ニュージーランド | | 承認 | 拒否 | | ------- | ------------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nz | Person-nz | | 町名・番地 | Mount Wellington Highway | Mount Wellington Highway | | 番地等 | 286 | 286 | | 郵便番号 | 6011 | 6011 | | 市区町村 | Auckland | Wellington | | 電話番号 | +6427555290 | +642993007712 | | メールアドレス | customer@email.nz | customer+denied@email.nz | #### ノルウェー | | 承認済み | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 01-08-1970 | 01-08-1970 | | 名 | Jane | テスト | | 姓 | テスト | Person-no | | メールアドレス | customer@email.no | customer+denied@email.no | | 個人番号 | NO1087000571 | NO1087000148 | | 町名・番地 | Edvard Munchs Plass | Sæffleberggate | | 番地 | 1 | 56 | | 市区町村 | Oslo | Oslo | | 郵便番号 | 0194 | 0563 | | 電話番号 | +4740123456 | +4740123457 | #### ポーランド | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 05-05-1967 | 05-05-1967 | | 名 | テスト | テスト | | 姓 | Person-pl | Person-pl | | 町名・番地 | Ul. Górczewska | Ul. Górczewska | | 番地等 | 124 | 124 | | 郵便番号 | 01-460 | 01-460 | | 市区町村 | Warszawa | Warszawa | | 電話番号 | +48795222223 | +48795223325 | | メールアドレス | customer@email.pl | customer+denied@email.pl | #### ポルトガル | | 承認 | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-pt | Person-pt | | 町名・番地 | Avenida Dom João II | Avenida Dom João II | | 番地等 | 40 | 40 | | 郵便番号 | 1990-094 | 1990-094 | | 市区町村 | Lisboa | Lisboa | | 電話番号 | +351935556731 | +351915593837 | | メールアドレス | customer@email.pt | customer+denied@email.pt | #### ルーマニア | | 承認されました | 拒否 | | ------------ | ----------------- | ------------------------ | | 生年月日 | 1970 年 12 月 25 日 | 1970 年 12 月 25 日 | | 名 | テスト | テスト | | 姓 | Person-ro | Person-ro | | メール | customer@email.ro | customer+denied@email.ro | | 町名・番地 | Drumul Taberei | Drumul Taberei | | 番地 | 35 | 35 | | 市区町村 | București | București | | セクター | Sectorul 6 | Sectorul 6 | | 郵便番号 | 061357 | 061357 | | 電話 | +40741209876 | +40707127444 | | 個人識別番号 (CNP) | 1701225193558 | | #### スペイン | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | DNI/NIE | 99999999R | 99999999R | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-es | Person-es | | メールアドレス | customer@email.es | customer+denied@email.es | | 町名・番地 | C. de Atocha | C. de Atocha | | 番地 | 27 | 27 | | 市区町村 | Madrid | Madrid | | 郵便番号 | 28012 | 28012 | | 電話番号 | +34672563009 | +34682425101 | #### スウェーデン | | 承認済み | 拒否 | | ------- | ----------------------- | ------------------------ | | 生年月日 | 21-03-1941 | 28-10-1941 | | 名 | Alice | テスト | | 姓 | テスト | Person-se | | メールアドレス | customer@email.se | customer+denied@email.se | | 町名・番地 | Södra Blasieholmshamnen | Karlaplan | | 番地 | 2 | 3 | | 市区町村 | Stockholm | Stockholm | | 郵便番号 | 11 148 | 11 460 | | 電話番号 | +46701740615 | +46701740620 | #### スイス | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1990 | 01-01-2000 | | 名 | 受付済み | 顧客 | | 姓 | Person-ch | Person-ch | | 町名・番地 | Augustinergasse | Bahnhofstrasse | | 番地等 | 2 | 77 | | 郵便番号 | 4051 | 8001 | | 市区町村 | Basel | Zürich | | 電話番号 | +41758680000 | +41758680001 | | メールアドレス | customer@email.ch | customer+denied@email.ch | #### イギリス | | 承認済み | 拒否 | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-uk | Person-uk | | メールアドレス | customer@email.uk | customer+denied@email.uk | | 町名・番地 | New Burlington Street | New Burlington Street | | 番地 | 10 | 10 | | アパート | Apt 214 | Apt 214 | | 郵便番号 | W1S 3BE | W1S 3BE | | 市区町村 | London | London | | 電話番号 | +447755564318 | +447355505530 | #### アメリカ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 07-10-1970 | 07-10-1970 | | 名 | テスト | テスト | | 姓 | Person-us | Person-us | | メールアドレス | customer@email.us | customer+denied@email.us | | 町名・番地 | Amsterdam Ave | Amsterdam Ave | | 番地 | 509 | 509 | | 市区町村 | New York | New York | | 州 | New York | New York | | 郵便番号 | 10024-3941 | 10024-3941 | | 電話番号 | +13106683312 | +13106354386 | ### 2 段階認証 6 桁の数字であれば、2 段階認証コードとして有効です。`999999` を使用すると、認証は失敗します。 ### 返済方法 Klarna のフロー内では、以下のテスト値を使用し、さまざまな返済方法を試すことができます。 | タイプ | 値 | | -------- | ---------------------------------------------------------- | | 口座引き落とし | DE11520513735120710131 | | 銀行振込 | デモの銀行 | | クレジットカード | - 番号: 4111 1111 1111 1111 - CVV: 123 - 有効期限: 任意の将来日付 | | デビットカード | - カード番号:4012 8888 8888 1881 - CVV: 123 - 有効期限: 任意の将来日付 | ## Optional: オーソリとキャプチャーの分離 Klarna は[オーソリとキャプチャの分離](https://docs.stripe.com/payments/place-a-hold-on-a-payment-method.md)に対応しています。支払いから顧客への商品の配送までに遅延が生じた場合、まず支払いをオーソリし、後でキャプチャーします。キャプチャーされた時点で、Klarna は顧客に明細書を送り、必要となる以降の支払いの期日を作成します。**オーソリされた Klarna の支払いは、オーソリから 28 日以内にキャプチャーする必要があります** 。キャンセルされない場合、オーソリは自動的にキャンセルされ、支払いをキャプチャーできなくなります。 1. オーソリのみ行うように Stripe に指示する オーソリとキャプチャーを分離することを指定するには、PaymentIntent の作成時に、[capture_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-capture_method) を `manual` に設定します。このパラメーターは、顧客の Klarna アカウントの金額のみをオーソリするよう Stripe に指示します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur \ -d capture_method=manual ``` 1. 売上をキャプチャーする 承認が完了すると、PaymentIntent の [ステータス](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-status)は `requires_capture` に移行します。承認済みの売上をキャプチャーするには、PaymentIntent の [キャプチャー](https://docs.stripe.com/api/payment_intents/capture.md)リクエストを作成します。デフォルトでは承認済みの総額がキャプチャーされます。これを超える金額をキャプチャーすることはできませんが、これより少ない金額をキャプチャーすることは可能です。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}}/capture \ -u "<>:" \ -d amount_to_capture=750 ``` 1. (任意)オーソリをキャンセルする Klarna は、Klarna 内での顧客の総計購買力に対して、承認された決済件数を計算します。このため、フルフィルメントを行えない承認済みの決済 (商品を配送できないなど) は、それが明らかになり次第、早急にキャンセルする必要があります。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}}/cancel \ -u "<>:" \ -d cancellation_reason=abandoned ``` ## Optional: 支払い後のイベントを処理する 支払いが完了すると、Stripe は [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) イベントを送信します。ダッシュボード、カスタム *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests)、またはパートナーソリューションを使用してこれらのイベントを受信し、また、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行します。 クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアント側では、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了したりする可能性があります。また、悪意を持つクライアントがレスポンスを不正操作する恐れもあります。非同期型のイベントをリッスンするよう構築済みのシステムを設定することで、これ以降はより多くの決済手段を簡単に受け付けられるようになります。[サポートされているすべての決済手段の違い](https://stripe.com/payments/payment-methods-guide)をご確認ください。 - **ダッシュボードでイベントを手動で処理する** ダッシュボードを使用して、テスト決済を[ダッシュボードで表示](https://dashboard.stripe.com/test/payments)したり、メール領収書を送信したり、入金を処理したり、失敗した決済を再試行したりできます。 - **Custom Webhook を構築する** [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI. - **構築済みアプリを導入する** パートナーアプリケーションを統合することで、[自動化](https://stripe.partners/?f_category=automation)や[マーケティング/セールス](https://stripe.partners/?f_category=marketing-and-sales)などの一般的なビジネスイベントを処理します。 ## Optional: Klarna 支払いページをカスタマイズする - **Klarna フォームを事前入力する** 顧客が延べ払いオプションを使用して Klarna に決済することを選択すると (後払い、分割払い、融資など)、Klarna は、リスク評価と承認のために十分な情報を収集します。情報の種類は、顧客の国によって異なります。ほとんどのヨーロッパの国では、完全な請求先住所と生年月日です。この情報は API を通じて渡すことができ、顧客がページに到着する前にフォームが事前入力されます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur \ -d confirm=true \ --data-urlencode "return_url=https://example.com/checkout/complete" \ -d "payment_method_data[type]=klarna" \ --data-urlencode "payment_method_data[billing_details][email]=customer@example.com" \ -d "payment_method_data[billing_details][name]=Jenny Rosen" \ --data-urlencode "payment_method_data[billing_details][phone]=+4915142321555" \ -d "payment_method_data[billing_details][address][line1]=Alexanderplatz 1" \ -d "payment_method_data[billing_details][address][city]=Berlin" \ -d "payment_method_data[billing_details][address][postal_code]=10551" \ -d "payment_method_data[billing_details][address][country]=DE" \ -d "payment_method_data[klarna][dob][day]=10" \ -d "payment_method_data[klarna][dob][month]=10" \ -d "payment_method_data[klarna][dob][year]=1990" ``` ![API からの請求詳細が事前入力され、英語で表示されるようにカスタマイズされた Klarna の支払いページのスクリーンショット](https://b.stripecdn.com/docs-statics-srv/assets/klarna-kpp-prefilled-customized.75932cc9aa3223960aa2fcf769c1ce62.png) Klarna の支払いページは、API からの請求書詳細が事前入力され、カスタマイズされてドイツの顧客に英語で表示されます。 ## Optional: PaymentIntent にラインアイテムを追加する > #### Klarna との統合項目 > > Klarna を導入する際に承認率を最適化するには、`line_items` データを含めて買い物客のカートの中身を表します。先行提供版については、[支払い項目](https://docs.stripe.com/payments/payment-line-items.md)をご覧ください。 ## 失敗した支払い Klarna は、取引を受け付けるか拒否するかを決定する際に複数の要因を考慮します (買い手が Klarna を使用している期間、顧客が返済する必要のある未払い額、現在の注文の金額など)。 顧客が後払いを選択すると、Klarna は取引を受け付ける前にリスク評価を行います。Klarna は、リスク評価の結果が良好でなかったり、取引金額が大きかったり、顧客に多額の未払いの負債があったりすると、取引を拒否することがあります。そのため、決済フローに `card` などの他の支払いオプションを提示することをお勧めします。このような場合、[PaymentMethod](https://docs.stripe.com/api/payment_methods/object.md) は解除され、[PaymentInten](https://docs.stripe.com/api/payment_intents/object.md)オブジェクトのステータスは自動的に `requires_payment_method` に変わります。 顧客は、Klarna のサイトにリダイレクトされてから 48 時間以内に決済を完了する必要があります。48 時間経過しても対応しなかった場合、[PaymentMethod](https://docs.stripe.com/api/payment_methods/object.md) の関連付けが解除され、[PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) オブジェクトのステータスは自動的に `requires_action` から `requires_payment_method` に移行します。 このようなケースでは、決済フローに表示される別の支払いオプションで再試行するように顧客に通知します。 ### Klarna のレート制限 Klarna への API リクエストには、Stripe の [API 全体のレート制限](https://docs.stripe.com/rate-limits.md) を超える追加のレート制限が適用されます。これらの制限は、行う API リクエストの形状によって異なる場合があります。一般に、毎秒 50 を超えるリクエストを行うと、HTTP ステータスコード `400` または `402` の応答の形式でレート制限が表示されることがあります。使用量がこれらのレベルに達するのではないかとご心配な場合は、Klarna がケースバイケースでこれらの制限を増やすことができる可能性がありますので、Stripe まで[お問い合わせください](https://support.stripe.com)。 ### エラーメッセージ Klarna 支払いが失敗すると、通常、以下のエラーコードのいずれかが返されます。これらのコードは、[last_payment_error](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-last_payment_error) API オブジェクトに表示されます。 > `2023-08-16` API バージョンより前は、すべての Klarna エラーが [payment_intent_authentication_failure](https://docs.stripe.com/error-codes.md#payment_intent_authentication_failure) として報告されていました。API バージョンが最新であることを確認して、以下のエラー詳細をご覧ください。 | エラーコード | 説明 | | ----------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | | [payment_method_customer_decline](https://docs.stripe.com/error-codes.md#payment-method-customer-decline) | 顧客が Klarna のページで決済をキャンセルしました | | [payment_method_provider_decline](https://docs.stripe.com/error-codes.md#payment-method-provider-decline) | Klarna が顧客の支払いを拒否しました | | [payment_intent_payment_attempt_expired](https://docs.stripe.com/error-codes.md#payment-intent-payment-attempt-expired) | 顧客が Klarna のページで購入を完了しないまま、支払いセッションの有効期限が切れました | | [payment_method_not_available](https://docs.stripe.com/error-codes.md#payment-method-not-available) | Klarna を使用しようとしたときに予期しないエラーが発生しました | # React Native > This is a React Native for when payment-ui is mobile and platform is react-native. View the full page at https://docs.stripe.com/payments/klarna/accept-a-payment?payment-ui=mobile&platform=react-native. アプリで Klarna を受け付けるには、顧客が支払いを認証するための Webview を表示します。その後、顧客はアプリに戻り、お客様は支払いが成功したか失敗したかをすぐに*確認* (Confirming an intent indicates that the customer intends to use the current or provided payment method. Upon confirmation, the intent attempts to initiate the portions of the flow that have real-world side effects)できます。 ## Stripe を設定する [サーバ側] [クライアント側] ### サーバ側 この組み込みには、Stripe API と通信するエンドポイントがサーバ上に必要です。Stripe の公式ライブラリを使用して、サーバから Stripe API にアクセスします。 #### Ruby ```bash # Available as a gem sudo gem install stripe ``` ```ruby # If you use bundler, you can add this line to your Gemfile gem 'stripe' ``` ### クライアント側 [React Native SDK](https://github.com/stripe/stripe-react-native) はオープンソースであり、詳細なドキュメントが提供されています。内部では、[ネイティブの iOS](https://github.com/stripe/stripe-ios) および [Android](https://github.com/stripe/stripe-android) の SDK を使用します。Stripe の React Native SDK をインストールするには、プロジェクトのディレクトリーで (使用するパッケージマネージャーによって異なる) 次のいずれかのコマンドを実行します。 #### yarn ```bash yarn add @stripe/stripe-react-native ``` #### npm ```bash npm install @stripe/stripe-react-native ``` 次に、その他の必要な依存関係をインストールします。 - iOS の場合は、**ios** ディレクトリに移動して `pod install` を実行し、必要なネイティブ依存関係もインストールします。 - Android の場合は、依存関係をインストールする必要はありません。 > [公式の TypeScript ガイド](https://reactnative.dev/docs/typescript#adding-typescript-to-an-existing-project)に従って TypeScript のサポートを追加することをお勧めします。 ### Stripe の初期化 React Native アプリで Stripe を初期化するには、決済画面を `StripeProvider` コンポーネントでラップするか、`initStripe` 初期化メソッドを使用します。`publishableKey` の API [公開可能キー](https://docs.stripe.com/keys.md#obtain-api-keys)のみが必要です。次の例は、`StripeProvider` コンポーネントを使用して Stripe を初期化する方法を示しています。 ```jsx import { useState, useEffect } from 'react'; import { StripeProvider } from '@stripe/stripe-react-native'; function App() { const [publishableKey, setPublishableKey] = useState(''); const fetchPublishableKey = async () => { const key = await fetchKey(); // fetch key from your server here setPublishableKey(key); }; useEffect(() => { fetchPublishableKey(); }, []); return ( {/* Your app code here */} ); } ``` > テストおよび開発時には API の[テストキー](https://docs.stripe.com/keys.md#obtain-api-keys)を使用し、アプリの公開時には[本番環境](https://docs.stripe.com/keys.md#test-live-modes)キーを使用します。 ## PaymentIntent を作成する [サーバー側] [クライアント側] Stripe は [PaymentIntent](https://docs.stripe.com/api/payment_intents.md) オブジェクトを使用して、顧客から支払いを回収するお客様の意図を示し、決済プロセス全体を通して請求の実施と支払い状態の変化を追跡します。 ### サーバー側 まず、サーバーで `PaymentIntent` を作成し、回収する金額と通貨を指定します。[Payment Intents API](https://docs.stripe.com/payments/payment-intents.md) を使用した組み込みをすでにお持ちの場合には、`klarna` を `PaymentIntent` の[決済手段タイプ](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types)のリストに追加します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur ``` ### クライアント側 PaymentIntent には *client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。これを React Native アプリで使用することで、PaymentIntent オブジェクト全体を渡すことなく安全に支払いプロセスを完了できます。アプリで、サーバーの PaymentIntent をリクエストし、その client secret を保存します。 ```javascript function PaymentScreen() { // ... const fetchPaymentIntentClientSecret = async () => { const response = await fetch(`${API_URL}/create-payment-intent`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ currency: 'eur', }), }); const {clientSecret} = await response.json(); return clientSecret; }; return ...; } ``` ## Stripe に支払いを送信する [クライアント側] Stripe に支払いを送信するには、作成した PaymentIntent の client secret が必要です。これを `confirmPayment` のコールに含めます。 ```javascript import {Picker} from '@react-native-picker/picker'; import {confirmPayment} from '@stripe/stripe-react-native'; export default function MyPaymentScreen() { const handlePayPress = async () => { // Fetch the intent client secret from the backend. // See `fetchPaymentIntentClientSecret()`'s implementation above. const clientSecret = await fetchPaymentIntentClientSecret(); const {error, paymentIntent} = await confirmPayment(clientSecret, { paymentMethodType: 'Klarna' }, }); if (error) { console.log('Payment confirmation error', error.message); // Update UI to prompt user to retry payment (and possibly another payment method) } else if (paymentIntent) { Alert.alert('Success', `The payment was confirmed successfully!`); } }; ``` ## Klarna の組み込みをテストする > Klarna はセッションの追跡に クッキーを使用します。さまざまな顧客の所在地をテストするには、前のセッションで Klarna サンドボックスからログアウトし、関連するトリガーを使用します。 下記では、現在対応している顧客の国のテストデータを特別に選択しています。サンドボックスでは、Klarna は指定されたメールアドレスに基づいて取引を承認または拒否します。 #### オーストラリア | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 03-05-1994 | | 名 | テスト | John | | 姓 | Person-au | snow | | 町名・番地 | Wharf St | Silverwater Rd | | 番地等 | 4 | 1-5 | | 郵便番号 | 4877 | 2128 | | 市区町村 | Port Douglas | Silverwater | | 地域 | QLD | NSW | | 電話番号 | +61473752244 | +61473763254 | | メールアドレス | customer@email.au | customer+denied@email.au | #### オーストリア | | 承認済み | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-at | Person-at | | メールアドレス | customer@email.at | customer+denied@email.at | | 町名・番地 | Mariahilfer Straße | Mariahilfer Straße | | 番地 | 47 | 47 | | 市区町村 | Wien | Wien | | 郵便番号 | 1060 | 1060 | | 電話番号 | +4306762600456 | +4306762600745 | #### ベルギー | | 承認済み | 拒否済み | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-be | Person-be | | メールアドレス | customer@email.be | customer+denied@email.be | | 町名・番地 | Grote Markt | Grote Markt | | 番地 | 1 | 1 | | 市 | Brussel | Brussel | | 郵便番号 | 1000 | 1000 | | 電話番号 | +32485121291 | +32485212123 | #### カナダ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ca | Person-ca | | 町名・番地 | 2693 Byron Rd | 2693 Byron Rd | | 郵便番号 | V7H 1L9 | V7H 1L9 | | 市区町村 | North Vancouver | North Vancouver | | 地域 | BC | BC | | 電話番号 | +15197438620 | +15197308624 | | メールアドレス | customer@email.ca | customer+denied@email.ca | #### チェコ | | 承認 | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 01-01-1970 | 27-06-1992 | | 名 | テスト | テスト | | 姓 | Person-cz | Person-cz | | メールアドレス | customer@email.cz | customer+denied@email.cz | | 町名・番地 | Zazvorkova 1480/11 | Zázvorkova 1480/11 | | 郵便番号 | 155 00 | 155 00 | | 市区町村 | Praha | PRAHA 13 | | 電話番号 | +420771613715 | +420771623691 | #### デンマーク | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-dk | Person-dk | | メールアドレス | customer@email.dk | customer+denied@email.dk | | 町名・番地 | Dantes Plads | Nygårdsvej | | 番地 | 7 | 65 | | 市区町村 | København Ø | København Ø | | 郵便番号 | 1556 | 2100 | | 電話番号 | +4542555628 | +4552555348 | #### フィンランド | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1999 | 01-01-1999 | | 名 | テスト | Person FI | | 姓 | Person-fi | テスト | | メールアドレス | customer@email.fi | customer+denied@email.fi | | 町名・番地 | Mannerheimintie | Mannerheimintie | | 番地 | 34 | 34 | | 市区町村 | Helsinki | Helsinki | | 郵便番号 | 00100 | 00100 | | 電話番号 | +358401234567 | +358401234568 | #### フランス | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 10-07-1990 | 10-07-1990 | | 出生地 | パリ | パリ | | 名 | テスト | テスト | | 姓 | Person-fr | Person-fr | | メールアドレス | customer@email.fr | customer+denied@email.fr | | 町名・番地 | rue La Fayette | rue La Fayette | | 番地 | 33 | 33 | | 市区町村 | パリ | パリ | | 郵便番号 | 75009 | 75009 | | 電話番号 | +33689854321 | +33687984322 | #### ドイツ | | 承認済み | 拒否済み | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | 模擬 | テスト | | 姓 | 模擬 | Person-de | | メールアドレス | customer@email.de | customer+denied@email.de | | 町名・番地 | Neue Schönhauser Str. | Neue Schönhauser Str. | | 番地 | 2 | 2 | | 市 | Berlin | Berlin | | 郵便番号 | 10178 | 10178 | | 電話番号 | +49017614284340 | +49017610927312 | #### ギリシャ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 納税者番号 | 090000045 | 090000045 | | 生年月日 | 01-01-1960 | 11-11-1970 | | 名 | テスト | テスト | | 姓 | Person-gr | Test-gr | | メールアドレス | customer@email.gr | customer+denied@email.gr | | 町名・番地 | Kephisias | Baralo | | 番地 | 37 | 56 | | 郵便番号 | 151 23 | 123 67 | | 市区町村 | Athina | Athina | | 電話番号 | +306945553624 | +306945553625 | #### アイルランド | | 承認済み | 拒否 | | -------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ie | Person-ie | | メール | customer@email.ie | customer+denied@email.ie | | 町名・番地 | King Street South | King Street South | | 番地 | 30 | 30 | | 市区町村 | ダブリン | ダブリン | | EIR Code | D02 C838 | D02 C838 | | 電話番号 | +353855351400 | +353855351401 | #### イタリア | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 01-01-1980 | | 名 | テスト | テスト | | 姓 | Person-it | Person-it | | メールアドレス | customer@email.it | customer+denied@email.it | | 納税番号 | RSSBNC80A41H501B | RSSBNC80A41H501B | | 町名・番地 | Via Enrico Fermi | Via Enrico Fermi | | 番地 | 150 | 150 | | 市区町村 | Roma | Roma | | 郵便番号 | 00146 | 00146 | | 電話番号 | +393339741231 | +393312232389 | #### オランダ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nl | Person-nl | | メールアドレス | customer@email.nl | customer+denied@email.nl | | 町名・番地 | Osdorpplein | Osdorpplein | | 番地 | 137 | 137 | | 市区町村 | Amsterdam | Amsterdam | | 郵便番号 | 1068 SR | 1068 SR | | 電話番号 | +31689124321 | +31632167678 | #### ニュージーランド | | 承認 | 拒否 | | ------- | ------------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nz | Person-nz | | 町名・番地 | Mount Wellington Highway | Mount Wellington Highway | | 番地等 | 286 | 286 | | 郵便番号 | 6011 | 6011 | | 市区町村 | Auckland | Wellington | | 電話番号 | +6427555290 | +642993007712 | | メールアドレス | customer@email.nz | customer+denied@email.nz | #### ノルウェー | | 承認済み | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 01-08-1970 | 01-08-1970 | | 名 | Jane | テスト | | 姓 | テスト | Person-no | | メールアドレス | customer@email.no | customer+denied@email.no | | 個人番号 | NO1087000571 | NO1087000148 | | 町名・番地 | Edvard Munchs Plass | Sæffleberggate | | 番地 | 1 | 56 | | 市区町村 | Oslo | Oslo | | 郵便番号 | 0194 | 0563 | | 電話番号 | +4740123456 | +4740123457 | #### ポーランド | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 05-05-1967 | 05-05-1967 | | 名 | テスト | テスト | | 姓 | Person-pl | Person-pl | | 町名・番地 | Ul. Górczewska | Ul. Górczewska | | 番地等 | 124 | 124 | | 郵便番号 | 01-460 | 01-460 | | 市区町村 | Warszawa | Warszawa | | 電話番号 | +48795222223 | +48795223325 | | メールアドレス | customer@email.pl | customer+denied@email.pl | #### ポルトガル | | 承認 | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-pt | Person-pt | | 町名・番地 | Avenida Dom João II | Avenida Dom João II | | 番地等 | 40 | 40 | | 郵便番号 | 1990-094 | 1990-094 | | 市区町村 | Lisboa | Lisboa | | 電話番号 | +351935556731 | +351915593837 | | メールアドレス | customer@email.pt | customer+denied@email.pt | #### ルーマニア | | 承認されました | 拒否 | | ------------ | ----------------- | ------------------------ | | 生年月日 | 1970 年 12 月 25 日 | 1970 年 12 月 25 日 | | 名 | テスト | テスト | | 姓 | Person-ro | Person-ro | | メール | customer@email.ro | customer+denied@email.ro | | 町名・番地 | Drumul Taberei | Drumul Taberei | | 番地 | 35 | 35 | | 市区町村 | București | București | | セクター | Sectorul 6 | Sectorul 6 | | 郵便番号 | 061357 | 061357 | | 電話 | +40741209876 | +40707127444 | | 個人識別番号 (CNP) | 1701225193558 | | #### スペイン | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | DNI/NIE | 99999999R | 99999999R | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-es | Person-es | | メールアドレス | customer@email.es | customer+denied@email.es | | 町名・番地 | C. de Atocha | C. de Atocha | | 番地 | 27 | 27 | | 市区町村 | Madrid | Madrid | | 郵便番号 | 28012 | 28012 | | 電話番号 | +34672563009 | +34682425101 | #### スウェーデン | | 承認済み | 拒否 | | ------- | ----------------------- | ------------------------ | | 生年月日 | 21-03-1941 | 28-10-1941 | | 名 | Alice | テスト | | 姓 | テスト | Person-se | | メールアドレス | customer@email.se | customer+denied@email.se | | 町名・番地 | Södra Blasieholmshamnen | Karlaplan | | 番地 | 2 | 3 | | 市区町村 | Stockholm | Stockholm | | 郵便番号 | 11 148 | 11 460 | | 電話番号 | +46701740615 | +46701740620 | #### スイス | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1990 | 01-01-2000 | | 名 | 受付済み | 顧客 | | 姓 | Person-ch | Person-ch | | 町名・番地 | Augustinergasse | Bahnhofstrasse | | 番地等 | 2 | 77 | | 郵便番号 | 4051 | 8001 | | 市区町村 | Basel | Zürich | | 電話番号 | +41758680000 | +41758680001 | | メールアドレス | customer@email.ch | customer+denied@email.ch | #### イギリス | | 承認済み | 拒否 | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-uk | Person-uk | | メールアドレス | customer@email.uk | customer+denied@email.uk | | 町名・番地 | New Burlington Street | New Burlington Street | | 番地 | 10 | 10 | | アパート | Apt 214 | Apt 214 | | 郵便番号 | W1S 3BE | W1S 3BE | | 市区町村 | London | London | | 電話番号 | +447755564318 | +447355505530 | #### アメリカ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 07-10-1970 | 07-10-1970 | | 名 | テスト | テスト | | 姓 | Person-us | Person-us | | メールアドレス | customer@email.us | customer+denied@email.us | | 町名・番地 | Amsterdam Ave | Amsterdam Ave | | 番地 | 509 | 509 | | 市区町村 | New York | New York | | 州 | New York | New York | | 郵便番号 | 10024-3941 | 10024-3941 | | 電話番号 | +13106683312 | +13106354386 | ### 2 段階認証 6 桁の数字であれば、2 段階認証コードとして有効です。`999999` を使用すると、認証は失敗します。 ### 返済方法 Klarna のフロー内では、以下のテスト値を使用し、さまざまな返済方法を試すことができます。 | タイプ | 値 | | -------- | ---------------------------------------------------------- | | 口座引き落とし | DE11520513735120710131 | | 銀行振込 | デモの銀行 | | クレジットカード | - 番号: 4111 1111 1111 1111 - CVV: 123 - 有効期限: 任意の将来日付 | | デビットカード | - カード番号:4012 8888 8888 1881 - CVV: 123 - 有効期限: 任意の将来日付 | ## Optional: オーソリとキャプチャーを分離する Klarna は[オーソリとキャプチャの分離](https://docs.stripe.com/payments/place-a-hold-on-a-payment-method.md)に対応しています。支払いから顧客への商品の配送までに遅延が生じた場合、まず支払いをオーソリし、後でキャプチャーします。キャプチャーされた時点で、Klarna は顧客に明細書を送り、必要となる以降の支払いの期日を作成します。**オーソリされた Klarna の支払いは、オーソリから 28 日以内にキャプチャーする必要があります** 。キャンセルされない場合、オーソリは自動的にキャンセルされ、支払いをキャプチャーできなくなります。 1. オーソリのみ行うように Stripe に指示する オーソリとキャプチャーを分離することを指定するには、PaymentIntent の作成時に、[capture_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-capture_method) を `manual` に設定します。このパラメーターは、顧客の Klarna アカウントの金額のみをオーソリするよう Stripe に指示します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur \ -d capture_method=manual ``` 1. 売上をキャプチャーする 承認が完了すると、PaymentIntent の [ステータス](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-status)は `requires_capture` に移行します。承認済みの売上をキャプチャーするには、PaymentIntent の [キャプチャー](https://docs.stripe.com/api/payment_intents/capture.md)リクエストを作成します。デフォルトでは承認済みの総額がキャプチャーされます。これを超える金額をキャプチャーすることはできませんが、これより少ない金額をキャプチャーすることは可能です。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}}/capture \ -u "<>:" \ -d amount_to_capture=750 ``` 1. (任意)オーソリをキャンセルする Klarna は、Klarna 内での顧客の総計購買力に対して、承認された決済件数を計算します。このため、フルフィルメントを行えない承認済みの決済 (商品を配送できないなど) は、それが明らかになり次第、早急にキャンセルする必要があります。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}}/cancel \ -u "<>:" \ -d cancellation_reason=abandoned ``` ## Optional: 支払い後のイベントを処理する 支払いが完了すると、Stripe は [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) イベントを送信します。ダッシュボード、カスタム *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests)、またはパートナーソリューションを使用してこれらのイベントを受信し、また、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行します。 クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアント側では、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了したりする可能性があります。また、悪意を持つクライアントがレスポンスを不正操作する恐れもあります。非同期型のイベントをリッスンするよう構築済みのシステムを設定することで、これ以降はより多くの決済手段を簡単に受け付けられるようになります。[サポートされているすべての決済手段の違い](https://stripe.com/payments/payment-methods-guide)をご確認ください。 - **ダッシュボードでイベントを手動で処理する** ダッシュボードを使用して、テスト決済を[ダッシュボードで表示](https://dashboard.stripe.com/test/payments)したり、メール領収書を送信したり、入金を処理したり、失敗した決済を再試行したりできます。 - **Custom Webhook を構築する** [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI. - **構築済みアプリを導入する** パートナーアプリケーションを統合することで、[自動化](https://stripe.partners/?f_category=automation)や[マーケティング/セールス](https://stripe.partners/?f_category=marketing-and-sales)などの一般的なビジネスイベントを処理します。 ## Optional: Klarna 支払いページをカスタマイズする - **Klarna フォームを事前入力する** 顧客が延べ払いオプションを使用して Klarna に決済することを選択すると (後払い、分割払い、融資など)、Klarna は、リスク評価と承認のために十分な情報を収集します。情報の種類は、顧客の国によって異なります。ほとんどのヨーロッパの国では、完全な請求先住所と生年月日です。この情報は API を通じて渡すことができ、顧客がページに到着する前にフォームが事前入力されます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur \ -d confirm=true \ --data-urlencode "return_url=https://example.com/checkout/complete" \ -d "payment_method_data[type]=klarna" \ --data-urlencode "payment_method_data[billing_details][email]=customer@example.com" \ -d "payment_method_data[billing_details][name]=Jenny Rosen" \ --data-urlencode "payment_method_data[billing_details][phone]=+4915142321555" \ -d "payment_method_data[billing_details][address][line1]=Alexanderplatz 1" \ -d "payment_method_data[billing_details][address][city]=Berlin" \ -d "payment_method_data[billing_details][address][postal_code]=10551" \ -d "payment_method_data[billing_details][address][country]=DE" \ -d "payment_method_data[klarna][dob][day]=10" \ -d "payment_method_data[klarna][dob][month]=10" \ -d "payment_method_data[klarna][dob][year]=1990" ``` ![API からの請求詳細が事前入力され、英語で表示されるようにカスタマイズされた Klarna の支払いページのスクリーンショット](https://b.stripecdn.com/docs-statics-srv/assets/klarna-kpp-prefilled-customized.75932cc9aa3223960aa2fcf769c1ce62.png) Klarna の支払いページは、API からの請求書詳細が事前入力され、カスタマイズされてドイツの顧客に英語で表示されます。 ## Optional: PaymentIntent にラインアイテムを追加する > #### Klarna との統合項目 > > Klarna を導入する際に承認率を最適化するには、`line_items` データを含めて買い物客のカートの中身を表します。先行提供版については、[支払い項目](https://docs.stripe.com/payments/payment-line-items.md)をご覧ください。 ## 失敗した支払い Klarna は、取引を受け付けるか拒否するかを決定する際に複数の要因を考慮します (買い手が Klarna を使用している期間、顧客が返済する必要のある未払い額、現在の注文の金額など)。 顧客が後払いを選択すると、Klarna は取引を受け付ける前にリスク評価を行います。Klarna は、リスク評価の結果が良好でなかったり、取引金額が大きかったり、顧客に多額の未払いの負債があったりすると、取引を拒否することがあります。そのため、決済フローに `card` などの他の支払いオプションを提示することをお勧めします。このような場合、[PaymentMethod](https://docs.stripe.com/api/payment_methods/object.md) は解除され、[PaymentInten](https://docs.stripe.com/api/payment_intents/object.md)オブジェクトのステータスは自動的に `requires_payment_method` に変わります。 顧客は、Klarna のサイトにリダイレクトされてから 48 時間以内に決済を完了する必要があります。48 時間経過しても対応しなかった場合、[PaymentMethod](https://docs.stripe.com/api/payment_methods/object.md) の関連付けが解除され、[PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) オブジェクトのステータスは自動的に `requires_action` から `requires_payment_method` に移行します。 このようなケースでは、決済フローに表示される別の支払いオプションで再試行するように顧客に通知します。 ### Klarna のレート制限 Klarna への API リクエストには、Stripe の [API 全体のレート制限](https://docs.stripe.com/rate-limits.md) を超える追加のレート制限が適用されます。これらの制限は、行う API リクエストの形状によって異なる場合があります。一般に、毎秒 50 を超えるリクエストを行うと、HTTP ステータスコード `400` または `402` の応答の形式でレート制限が表示されることがあります。使用量がこれらのレベルに達するのではないかとご心配な場合は、Klarna がケースバイケースでこれらの制限を増やすことができる可能性がありますので、Stripe まで[お問い合わせください](https://support.stripe.com)。 ### エラーメッセージ Klarna 支払いが失敗すると、通常、以下のエラーコードのいずれかが返されます。これらのコードは、[last_payment_error](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-last_payment_error) API オブジェクトに表示されます。 > `2023-08-16` API バージョンより前は、すべての Klarna エラーが [payment_intent_authentication_failure](https://docs.stripe.com/error-codes.md#payment_intent_authentication_failure) として報告されていました。API バージョンが最新であることを確認して、以下のエラー詳細をご覧ください。 | エラーコード | 説明 | | ----------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | | [payment_method_customer_decline](https://docs.stripe.com/error-codes.md#payment-method-customer-decline) | 顧客が Klarna のページで決済をキャンセルしました | | [payment_method_provider_decline](https://docs.stripe.com/error-codes.md#payment-method-provider-decline) | Klarna が顧客の支払いを拒否しました | | [payment_intent_payment_attempt_expired](https://docs.stripe.com/error-codes.md#payment-intent-payment-attempt-expired) | 顧客が Klarna のページで購入を完了しないまま、支払いセッションの有効期限が切れました | | [payment_method_not_available](https://docs.stripe.com/error-codes.md#payment-method-not-available) | Klarna を使用しようとしたときに予期しないエラーが発生しました | # ダイレクト API > This is a ダイレクト API for when payment-ui is direct-api. View the full page at https://docs.stripe.com/payments/klarna/accept-a-payment?payment-ui=direct-api. ## 決済手段を手動で一覧表示する [動的な決済手段](https://docs.stripe.com/payments/payment-methods/dynamic-payment-methods.md)の使用をお勧めします。この場合、Stripe は各顧客に最も関連性の高い決済手段を動的に表示してコンバージョンを最大化するロジックを処理します。[決済手段を手動](https://docs.stripe.com/payments/payment-methods/integration-options.md#listing-payment-methods-manually)で一覧表示する場合は、[PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) の作成時に [payment_method_types](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_types) リストで `klarna` を指定します。 ### PaymentIntent を作成する 決済成功率を最大化し、不審請求の申請を減らすには、Klarna 決済の[PaymentIntent を作成](https://docs.stripe.com/api/payment_intents/create.md)する際に次のパラメーターを渡します。 - [shipping](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-shipping): `name`、`address.line1`、`city`、`country`、および `postal_code`の各フィールドが定義されていて、空欄がないことを確認してください。 - [amount_details.line_items](https://docs.stripe.com/payments/payment-line-items.md) - [payment_method_data.billing_details](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-payment_method_data-billing_details):`name`、`address.line1`,`city`、`country`、および`postal_code`の各フィールドが定義されていて、空欄がないことを確認してください。 > [setup_future_usage](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-setup_future_usage) パラメーターを設定すると、その決済は 1 回限りの決済とは見なされません。これにより、利用[可能な決済オプション](https://docs.stripe.com/payments/klarna.md#payment-options)に影響が及び、[Payment Method Messaging Element](https://docs.stripe.com/elements/payment-method-messaging.md) と [Payment Element](https://docs.stripe.com/payments/payment-element.md) に顧客が利用できる決済プランが表示されなくなります。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[0]=klarna" \ -d amount=1099 \ -d currency=eur \ -d "amount_details[line_items][0][product_name]=Your product name" \ -d "amount_details[line_items][0][unit_cost]=1099" \ -d "amount_details[line_items][0][quantity]=1" \ -d "shipping[address][city]=Brothers" \ -d "shipping[address][country]=US" \ -d "shipping[address][line1]=27 Fredrick Ave" \ -d "shipping[address][postal_code]=97712" \ -d "shipping[address][state]=OR" \ -d "payment_method_data[billing_details][address][city]=Brothers" \ -d "payment_method_data[billing_details][address][country]=US" \ -d "payment_method_data[billing_details][address][line1]=27 Fredrick Ave" \ -d "payment_method_data[billing_details][address][postal_code]=97712" \ -d "payment_method_data[billing_details][address][state]=OR" \ --data-urlencode "payment_method_data[billing_details][email]=jenny.rosen@example.com" \ -d "payment_method_data[billing_details][name]=Jenny Rosen" ``` ### client secret を取得する PaymentIntent には、*client secret* (The client secret is a unique key returned from Stripe as part of a PaymentIntent. This key lets the client access important fields from the PaymentIntent (status, amount, currency) while hiding sensitive ones (metadata, customer)) が含まれています。これは、支払いプロセスを安全に完了するためにクライアント側で使用されます。client secret をクライアント側に渡す際は、いくつかの方法を使用できます。 #### 1 ページのアプリケーション ブラウザーの `fetch` 関数を使用して、サーバーのエンドポイントから client secret を取得します。この方法は、クライアント側が 1 ページのアプリケーションで、特に React などの最新のフロントエンドフレームワークで構築されている場合に最適です。client secret を処理するサーバーのエンドポイントを作成します。 #### Ruby ```ruby get '/secret' do intent = # ... Create or retrieve the PaymentIntent {client_secret: intent.client_secret}.to_json end ``` その後、クライアント側で JavaScript を使用して client secret を取得します。 ```javascript (async () => { const response = await fetch('/secret'); const {client_secret: clientSecret} = await response.json(); // Render the form using the clientSecret })(); ``` #### サーバ側のレンダリング サーバーからクライアントに client secret を渡します。この方法は、アプリケーションがブラウザーへの送信前に静的なコンテンツをサーバーで生成する場合に最適です。 決済フォームに [client_secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) を追加します。サーバー側のコードで、PaymentIntent から client secret を取得します。 #### Ruby ```erb
``` ```ruby get '/checkout' do @intent = # ... Fetch or create the PaymentIntent erb :checkout end ``` ## Stripe に決済をする このステップでは、[Stripe.js](https://docs.stripe.com/payments/elements.md) を使用してクライアントで Klarna の支払いを完了します。 ### Stripe.js を設定する 顧客が Klarna での支払いをクリックするときは、Stripe.js を使用してその支払いを Stripe に送信することをお勧めします。Stripe.js は、支払いフローを構築するための Stripe の基本的な JavaScript ライブラリです。これにより、以下で説明するリダイレクトなどの複雑な処理が自動的に行われ、今後、組み込みを他の支払い方法にも簡単に拡張できます。Stripe.js スクリプトを HTML ファイルのヘッダーに追加することで、決済ページにこのスクリプトを含めます。 ```html Checkout ``` 決済ページで以下の JavaScript を使用して、Stripe.js のインスタンスを作成します。 ```javascript // 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('<>'); ``` PaymentIntent オブジェクト全体をクライアントに送信するのではなく、その [クライアントシークレット](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) を使用します。これは、Stripe API リクエストを認証する API キーとは異なります。 クライアントシークレットは決済を確定できるため、慎重に取り扱う必要があります。記録したり、URL に埋め込んだり、当該の顧客以外に漏洩することがないようにしてください。 [stripe.confirmKlarnaPayment](https://docs.stripe.com/js/payment_intents/confirm_klarna_payment) を使用し、お客様のページからのリダイレクトを処理して決済を完了します。この機能に [return_url](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-return_url) を追加して、ユーザーが Klarna のウェブサイトまたはモバイルアプリで決済を完了した後に Stripe がユーザーをリダイレクトする場所を示します。 Klarna の決済ページで、顧客は自身の市場で提供されている決済オプションから選択します。[概要ページ](https://docs.stripe.com/payments/klarna.md#payment-options)の表で市場別の提供状況を確認してください。Klarna 決済ページのオプションを制限したり、事前選択したりすることはできません。この選択を消費者に任せることで、取引の機会が最大化されます。 ```javascript // 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` にリダイレクトし、以下の URL クエリーパラメーターを含めます。返品ページでは、これらを使用して PaymentIntent のステータスを取得し、顧客に支払いステータスを表示できます。 `return_url` を指定する際に、返品ページで使用する独自のクエリパラメーターを追加することもできます。 | パラメーター | 説明 | | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `payment_intent` | `PaymentIntent` の一意の識別子。 | | `payment_intent_client_secret` | `PaymentIntent` オブジェクトの [client secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret)。サブスクリプションの実装の場合、この client_secret は [`confirmation_secret`](https://docs.stripe.com/api/invoices/object.md#invoice_object-confirmation_secret) を通じて `Invoice` オブジェクトでも公開されます | 顧客が自社のサイトにリダイレクトされたら、`payment_intent_client_secret` を使用して PaymentIntent をクエリし、顧客に取引ステータスを表示できます。 顧客が選択した Klarna 決済オプションの詳細は、`charge` 時に [payment_method_details](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-klarna) プロパティで確認できます。使用可能な値は `pay_later`、`pay_with_financing`、`pay_now`、`pay_in_installments` の 4 種類です。これらのオプションの詳細については、Stripe の [Klarna 概要ページ](https://docs.stripe.com/payments/klarna.md#payment-options)をご覧ください。 Klarna の決済ページ各地域への適応に使用されるロケールは、[payment_method_details](https://docs.stripe.com/api/charges/object.md#charge_object-payment_method_details-klarna) プロパティでも確認できます。 ```json { "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", "created": 1445277809, "currency": "eur", "livemode": true, "statement_descriptor": null, "status": "succeeded", "type": "klarna", "usage": "single_use" } ], "object": "list", "has_more": false, "url": "/v1/charges?payment_intent=pi_1G1sgdKi6xqXeNtkldRRE6HT" }, "payment_method_options": { "klarna": {} }, "payment_method_types": [ "klarna" ], "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", "amount": 1099, "client_secret": "pi_1G1sgdKi6xqXeNtkldRRE6HT_secret_h9B56ObhTN72fQiBAuzcVPb2E", "confirmation_method": "automatic", "created": 1579259303, "currency": "eur", "livemode": true, "next_action": null } ``` ## 実装内容をテストする > Klarna はセッションの追跡に クッキーを使用します。さまざまな顧客の所在地をテストするには、前のセッションで Klarna サンドボックスからログアウトし、関連するトリガーを使用します。 下記では、現在対応している顧客の国のテストデータを特別に選択しています。サンドボックスでは、Klarna は指定されたメールアドレスに基づいて取引を承認または拒否します。 #### オーストラリア | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 03-05-1994 | | 名 | テスト | John | | 姓 | Person-au | snow | | 町名・番地 | Wharf St | Silverwater Rd | | 番地等 | 4 | 1-5 | | 郵便番号 | 4877 | 2128 | | 市区町村 | Port Douglas | Silverwater | | 地域 | QLD | NSW | | 電話番号 | +61473752244 | +61473763254 | | メールアドレス | customer@email.au | customer+denied@email.au | #### オーストリア | | 承認済み | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-at | Person-at | | メールアドレス | customer@email.at | customer+denied@email.at | | 町名・番地 | Mariahilfer Straße | Mariahilfer Straße | | 番地 | 47 | 47 | | 市区町村 | Wien | Wien | | 郵便番号 | 1060 | 1060 | | 電話番号 | +4306762600456 | +4306762600745 | #### ベルギー | | 承認済み | 拒否済み | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-be | Person-be | | メールアドレス | customer@email.be | customer+denied@email.be | | 町名・番地 | Grote Markt | Grote Markt | | 番地 | 1 | 1 | | 市 | Brussel | Brussel | | 郵便番号 | 1000 | 1000 | | 電話番号 | +32485121291 | +32485212123 | #### カナダ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ca | Person-ca | | 町名・番地 | 2693 Byron Rd | 2693 Byron Rd | | 郵便番号 | V7H 1L9 | V7H 1L9 | | 市区町村 | North Vancouver | North Vancouver | | 地域 | BC | BC | | 電話番号 | +15197438620 | +15197308624 | | メールアドレス | customer@email.ca | customer+denied@email.ca | #### チェコ | | 承認 | 拒否 | | ------- | ------------------ | ------------------------ | | 生年月日 | 01-01-1970 | 27-06-1992 | | 名 | テスト | テスト | | 姓 | Person-cz | Person-cz | | メールアドレス | customer@email.cz | customer+denied@email.cz | | 町名・番地 | Zazvorkova 1480/11 | Zázvorkova 1480/11 | | 郵便番号 | 155 00 | 155 00 | | 市区町村 | Praha | PRAHA 13 | | 電話番号 | +420771613715 | +420771623691 | #### デンマーク | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-dk | Person-dk | | メールアドレス | customer@email.dk | customer+denied@email.dk | | 町名・番地 | Dantes Plads | Nygårdsvej | | 番地 | 7 | 65 | | 市区町村 | København Ø | København Ø | | 郵便番号 | 1556 | 2100 | | 電話番号 | +4542555628 | +4552555348 | #### フィンランド | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1999 | 01-01-1999 | | 名 | テスト | Person FI | | 姓 | Person-fi | テスト | | メールアドレス | customer@email.fi | customer+denied@email.fi | | 町名・番地 | Mannerheimintie | Mannerheimintie | | 番地 | 34 | 34 | | 市区町村 | Helsinki | Helsinki | | 郵便番号 | 00100 | 00100 | | 電話番号 | +358401234567 | +358401234568 | #### フランス | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 10-07-1990 | 10-07-1990 | | 出生地 | パリ | パリ | | 名 | テスト | テスト | | 姓 | Person-fr | Person-fr | | メールアドレス | customer@email.fr | customer+denied@email.fr | | 町名・番地 | rue La Fayette | rue La Fayette | | 番地 | 33 | 33 | | 市区町村 | パリ | パリ | | 郵便番号 | 75009 | 75009 | | 電話番号 | +33689854321 | +33687984322 | #### ドイツ | | 承認済み | 拒否済み | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | 模擬 | テスト | | 姓 | 模擬 | Person-de | | メールアドレス | customer@email.de | customer+denied@email.de | | 町名・番地 | Neue Schönhauser Str. | Neue Schönhauser Str. | | 番地 | 2 | 2 | | 市 | Berlin | Berlin | | 郵便番号 | 10178 | 10178 | | 電話番号 | +49017614284340 | +49017610927312 | #### ギリシャ | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 納税者番号 | 090000045 | 090000045 | | 生年月日 | 01-01-1960 | 11-11-1970 | | 名 | テスト | テスト | | 姓 | Person-gr | Test-gr | | メールアドレス | customer@email.gr | customer+denied@email.gr | | 町名・番地 | Kephisias | Baralo | | 番地 | 37 | 56 | | 郵便番号 | 151 23 | 123 67 | | 市区町村 | Athina | Athina | | 電話番号 | +306945553624 | +306945553625 | #### アイルランド | | 承認済み | 拒否 | | -------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-ie | Person-ie | | メール | customer@email.ie | customer+denied@email.ie | | 町名・番地 | King Street South | King Street South | | 番地 | 30 | 30 | | 市区町村 | ダブリン | ダブリン | | EIR Code | D02 C838 | D02 C838 | | 電話番号 | +353855351400 | +353855351401 | #### イタリア | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1980 | 01-01-1980 | | 名 | テスト | テスト | | 姓 | Person-it | Person-it | | メールアドレス | customer@email.it | customer+denied@email.it | | 納税番号 | RSSBNC80A41H501B | RSSBNC80A41H501B | | 町名・番地 | Via Enrico Fermi | Via Enrico Fermi | | 番地 | 150 | 150 | | 市区町村 | Roma | Roma | | 郵便番号 | 00146 | 00146 | | 電話番号 | +393339741231 | +393312232389 | #### オランダ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nl | Person-nl | | メールアドレス | customer@email.nl | customer+denied@email.nl | | 町名・番地 | Osdorpplein | Osdorpplein | | 番地 | 137 | 137 | | 市区町村 | Amsterdam | Amsterdam | | 郵便番号 | 1068 SR | 1068 SR | | 電話番号 | +31689124321 | +31632167678 | #### ニュージーランド | | 承認 | 拒否 | | ------- | ------------------------ | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-nz | Person-nz | | 町名・番地 | Mount Wellington Highway | Mount Wellington Highway | | 番地等 | 286 | 286 | | 郵便番号 | 6011 | 6011 | | 市区町村 | Auckland | Wellington | | 電話番号 | +6427555290 | +642993007712 | | メールアドレス | customer@email.nz | customer+denied@email.nz | #### ノルウェー | | 承認済み | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 01-08-1970 | 01-08-1970 | | 名 | Jane | テスト | | 姓 | テスト | Person-no | | メールアドレス | customer@email.no | customer+denied@email.no | | 個人番号 | NO1087000571 | NO1087000148 | | 町名・番地 | Edvard Munchs Plass | Sæffleberggate | | 番地 | 1 | 56 | | 市区町村 | Oslo | Oslo | | 郵便番号 | 0194 | 0563 | | 電話番号 | +4740123456 | +4740123457 | #### ポーランド | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 05-05-1967 | 05-05-1967 | | 名 | テスト | テスト | | 姓 | Person-pl | Person-pl | | 町名・番地 | Ul. Górczewska | Ul. Górczewska | | 番地等 | 124 | 124 | | 郵便番号 | 01-460 | 01-460 | | 市区町村 | Warszawa | Warszawa | | 電話番号 | +48795222223 | +48795223325 | | メールアドレス | customer@email.pl | customer+denied@email.pl | #### ポルトガル | | 承認 | 拒否 | | ------- | ------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-pt | Person-pt | | 町名・番地 | Avenida Dom João II | Avenida Dom João II | | 番地等 | 40 | 40 | | 郵便番号 | 1990-094 | 1990-094 | | 市区町村 | Lisboa | Lisboa | | 電話番号 | +351935556731 | +351915593837 | | メールアドレス | customer@email.pt | customer+denied@email.pt | #### ルーマニア | | 承認されました | 拒否 | | ------------ | ----------------- | ------------------------ | | 生年月日 | 1970 年 12 月 25 日 | 1970 年 12 月 25 日 | | 名 | テスト | テスト | | 姓 | Person-ro | Person-ro | | メール | customer@email.ro | customer+denied@email.ro | | 町名・番地 | Drumul Taberei | Drumul Taberei | | 番地 | 35 | 35 | | 市区町村 | București | București | | セクター | Sectorul 6 | Sectorul 6 | | 郵便番号 | 061357 | 061357 | | 電話 | +40741209876 | +40707127444 | | 個人識別番号 (CNP) | 1701225193558 | | #### スペイン | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | DNI/NIE | 99999999R | 99999999R | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-es | Person-es | | メールアドレス | customer@email.es | customer+denied@email.es | | 町名・番地 | C. de Atocha | C. de Atocha | | 番地 | 27 | 27 | | 市区町村 | Madrid | Madrid | | 郵便番号 | 28012 | 28012 | | 電話番号 | +34672563009 | +34682425101 | #### スウェーデン | | 承認済み | 拒否 | | ------- | ----------------------- | ------------------------ | | 生年月日 | 21-03-1941 | 28-10-1941 | | 名 | Alice | テスト | | 姓 | テスト | Person-se | | メールアドレス | customer@email.se | customer+denied@email.se | | 町名・番地 | Södra Blasieholmshamnen | Karlaplan | | 番地 | 2 | 3 | | 市区町村 | Stockholm | Stockholm | | 郵便番号 | 11 148 | 11 460 | | 電話番号 | +46701740615 | +46701740620 | #### スイス | | 承認 | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 01-01-1990 | 01-01-2000 | | 名 | 受付済み | 顧客 | | 姓 | Person-ch | Person-ch | | 町名・番地 | Augustinergasse | Bahnhofstrasse | | 番地等 | 2 | 77 | | 郵便番号 | 4051 | 8001 | | 市区町村 | Basel | Zürich | | 電話番号 | +41758680000 | +41758680001 | | メールアドレス | customer@email.ch | customer+denied@email.ch | #### イギリス | | 承認済み | 拒否 | | ------- | --------------------- | ------------------------ | | 生年月日 | 1970/10/07 | 1970/10/07 | | 名 | テスト | テスト | | 姓 | Person-uk | Person-uk | | メールアドレス | customer@email.uk | customer+denied@email.uk | | 町名・番地 | New Burlington Street | New Burlington Street | | 番地 | 10 | 10 | | アパート | Apt 214 | Apt 214 | | 郵便番号 | W1S 3BE | W1S 3BE | | 市区町村 | London | London | | 電話番号 | +447755564318 | +447355505530 | #### アメリカ | | 承認済み | 拒否 | | ------- | ----------------- | ------------------------ | | 生年月日 | 07-10-1970 | 07-10-1970 | | 名 | テスト | テスト | | 姓 | Person-us | Person-us | | メールアドレス | customer@email.us | customer+denied@email.us | | 町名・番地 | Amsterdam Ave | Amsterdam Ave | | 番地 | 509 | 509 | | 市区町村 | New York | New York | | 州 | New York | New York | | 郵便番号 | 10024-3941 | 10024-3941 | | 電話番号 | +13106683312 | +13106354386 | 実働環境のテストのために、現地通貨の金額 `3500` を使用して、融資以外のすべての Klarna 支払いオプションをテストできます。たとえば、イタリアでの「3 回払い」をテストする場合は、35.00 EUR の取引を使用できます。 ### 2 段階認証 6 桁の数字であれば、2 段階認証コードとして有効です。`999999` を使用すると、認証は失敗します。 ### 返済方法 Klarna のフロー内では、以下のテスト値を使用し、さまざまな返済方法を試すことができます。 | タイプ | 値 | | -------- | ---------------------------------------------------------- | | 口座引き落とし | DE11520513735120710131 | | 銀行振込 | デモの銀行 | | クレジットカード | - 番号: 4111 1111 1111 1111 - CVV: 123 - 有効期限: 任意の将来日付 | | デビットカード | - カード番号:4012 8888 8888 1881 - CVV: 123 - 有効期限: 任意の将来日付 | ## 失敗した決済 Klarna は、取引を受け付けるか拒否するかを決定する際に複数の要因を考慮します (買い手が Klarna を使用している期間、顧客が返済する必要のある未払い額、現在の注文の金額など)。 顧客が後払いを選択すると、Klarna は取引を受け付ける前にリスク評価を行います。Klarna は、リスク評価の結果が良好でなかったり、取引金額が大きかったり、顧客に多額の未払いの負債があったりすると、取引を拒否することがあります。そのため、決済フローに `card` などの他の支払いオプションを提示することをお勧めします。このような場合、[PaymentMethod](https://docs.stripe.com/api/payment_methods/object.md) は解除され、[PaymentInten](https://docs.stripe.com/api/payment_intents/object.md)オブジェクトのステータスは自動的に `requires_payment_method` に変わります。 顧客は、Klarna のサイトにリダイレクトされてから 48 時間以内に決済を完了する必要があります。48 時間経過しても対応しなかった場合、[PaymentMethod](https://docs.stripe.com/api/payment_methods/object.md) の関連付けが解除され、[PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) オブジェクトのステータスは自動的に `requires_action` から `requires_payment_method` に移行します。 このようなケースでは、決済フローに表示される別の支払いオプションで再試行するように顧客に通知します。 ### Klarna のレート制限 Klarna への API リクエストには、Stripe の [API 全体のレート制限](https://docs.stripe.com/rate-limits.md) を超える追加のレート制限が適用されます。これらの制限は、行う API リクエストの形状によって異なる場合があります。一般に、毎秒 50 を超えるリクエストを行うと、HTTP ステータスコード `400` または `402` の応答の形式でレート制限が表示されることがあります。使用量がこれらのレベルに達するのではないかとご心配な場合は、Klarna がケースバイケースでこれらの制限を増やすことができる可能性がありますので、Stripe まで[お問い合わせください](https://support.stripe.com)。 ### エラーメッセージ Klarna 支払いが失敗すると、通常、以下のエラーコードのいずれかが返されます。これらのコードは、[last_payment_error](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-last_payment_error) API オブジェクトに表示されます。 > `2023-08-16` API バージョンより前は、すべての Klarna エラーが [payment_intent_authentication_failure](https://docs.stripe.com/error-codes.md#payment_intent_authentication_failure) として報告されていました。API バージョンが最新であることを確認して、以下のエラー詳細をご覧ください。 | エラーコード | 説明 | | ----------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------- | | [payment_method_customer_decline](https://docs.stripe.com/error-codes.md#payment-method-customer-decline) | 顧客が Klarna のページで決済をキャンセルしました | | [payment_method_provider_decline](https://docs.stripe.com/error-codes.md#payment-method-provider-decline) | Klarna が顧客の支払いを拒否しました | | [payment_intent_payment_attempt_expired](https://docs.stripe.com/error-codes.md#payment-intent-payment-attempt-expired) | 顧客が Klarna のページで購入を完了しないまま、支払いセッションの有効期限が切れました | | [payment_method_not_available](https://docs.stripe.com/error-codes.md#payment-method-not-available) | Klarna を使用しようとしたときに予期しないエラーが発生しました | ## オプションのカスタマイズ オプションで、Klarna 決済フロー(売上の承認とキャプチャーの分離など)と顧客とのやり取り(リダイレクトの処理など)に複数の異なるカスタマイズを実装できます。 ### 承認とキャプチャーの分離 Klarna は[オーソリとキャプチャの分離](https://docs.stripe.com/payments/place-a-hold-on-a-payment-method.md)に対応しています。支払いから顧客への商品の配送までに遅延が生じた場合、まず支払いをオーソリし、後でキャプチャーします。キャプチャーされた時点で、Klarna は顧客に明細書を送り、必要となる以降の支払いの期日を作成します。**オーソリされた Klarna の支払いは、オーソリから 28 日以内にキャプチャーする必要があります** 。キャンセルされない場合、オーソリは自動的にキャンセルされ、支払いをキャプチャーできなくなります。 1. オーソリのみ行うように Stripe に指示する オーソリとキャプチャーを分離することを指定するには、PaymentIntent の作成時に、[capture_method](https://docs.stripe.com/api/payment_intents/create.md#create_payment_intent-capture_method) を `manual` に設定します。このパラメーターは、顧客の Klarna アカウントの金額のみをオーソリするよう Stripe に指示します。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur \ -d capture_method=manual ``` 1. 売上をキャプチャーする 承認が完了すると、PaymentIntent の [ステータス](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-status)は `requires_capture` に移行します。承認済みの売上をキャプチャーするには、PaymentIntent の [キャプチャー](https://docs.stripe.com/api/payment_intents/capture.md)リクエストを作成します。デフォルトでは承認済みの総額がキャプチャーされます。これを超える金額をキャプチャーすることはできませんが、これより少ない金額をキャプチャーすることは可能です。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}}/capture \ -u "<>:" \ -d amount_to_capture=750 ``` 1. (任意)オーソリをキャンセルする Klarna は、Klarna 内での顧客の総計購買力に対して、承認された決済件数を計算します。このため、フルフィルメントを行えない承認済みの決済 (商品を配送できないなど) は、それが明らかになり次第、早急にキャンセルする必要があります。 ```curl curl https://api.stripe.com/v1/payment_intents/{{PAYMENTINTENT_ID}}/cancel \ -u "<>:" \ -d cancellation_reason=abandoned ``` ### Klarna リダイレクトを手動で処理する クライアント側で `confirmKlarnaPayment` を使用して Klarna のリダイレクトおよび支払いを処理するには、Stripe.js を使用することをお勧めします。Stripe.js を使用すると、他の決済手段にも対応するように実装を拡張できます。ただし、以下の手順に従って、お客様のサーバーに顧客を手動でリダイレクトすることもできます。 - タイプが `klarna` の [PaymentIntent (支払いインテント)](https://docs.stripe.com/api/payment_intents/object.md) を作成し、確定します。`return_url` フィールドに顧客の支払い後のリダイレクト URL を指定する必要があります。この URL には固有のクエリパラメーターを指定でき、リダイレクトフローの最終的な URL にはその値が含まれます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur \ -d confirm=true \ --data-urlencode "return_url=https://example.com/checkout/complete" \ -d "payment_method_data[type]=klarna" ``` - 作成される `PaymentIntent` のステータスは `requires_action` であり、`next_action` のタイプは `redirect_to_url` です。 #### JSON ```json {"status": "requires_action", "next_action": { "type": "redirect_to_url", "redirect_to_url": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/checkout/complete" } }, "id": "pi_1G1sgdKi6xqXeNtkldRRE6HT", "object": "payment_intent", "amount": 1099, "client_secret": "pi_1G1sgdKi6xqXeNtkldRRE6HT_secret_h9B56ObhTN72fQiBAuzcVPb2E", "confirmation_method": "automatic", "created": 1579259303, "currency": "eur", "livemode": true, "charges": { "data": [], "object": "list", "has_more": false, "url": "/v1/charges?payment_intent=pi_1G1sgdKi6xqXeNtkldRRE6HT" }, "payment_method_options": { "klarna": {} }, "payment_method_types": [ "klarna" ] } ``` - `next_action.redirect_to_url.url` プロパティで指定した URL に顧客をリダイレクトします。ここに示すコード例はおおまかなものであり、リダイレクト方法は、ご使用のウェブフレームワークによって異なる場合があります。 #### Ruby ```ruby if payment_intent.status == 'requires_action' && payment_intent.next_action.type == 'redirect_to_url' url = payment_intent.next_action.redirect_to_url.url redirect(url) end ``` 決済プロセスを完了した顧客は、ステップ 1 で設定した `return_url` に送られます。`payment_intent` と `payment_intent_client_secret` の URL クエリパラメーターが含まれています。`return_url` にクエリパラメーターがすでに含まれていた場合は、それらも保持されます。 支払いのステータスを確認するには、[Webhook を利用](https://docs.stripe.com/payments/payment-intents/verifying-status.md#webhooks)することをお勧めします。 ### 決済後のイベントを処理 支払いが完了すると、Stripe は [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) イベントを送信します。ダッシュボード、カスタム *Webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests)、またはパートナーソリューションを使用してこれらのイベントを受信し、また、顧客への注文確認メールの送信、データベースでの売上の記録、配送ワークフローの開始などのアクションを実行します。 クライアントからのコールバックを待つのではなく、これらのイベントをリッスンします。クライアント側では、コールバックが実行される前に顧客がブラウザーのウィンドウを閉じたり、アプリを終了したりする可能性があります。また、悪意を持つクライアントがレスポンスを不正操作する恐れもあります。非同期型のイベントをリッスンするよう構築済みのシステムを設定することで、これ以降はより多くの決済手段を簡単に受け付けられるようになります。[サポートされているすべての決済手段の違い](https://stripe.com/payments/payment-methods-guide)をご確認ください。 - **ダッシュボードでイベントを手動で処理する** ダッシュボードを使用して、テスト決済を[ダッシュボードで表示](https://dashboard.stripe.com/test/payments)したり、メール領収書を送信したり、入金を処理したり、失敗した決済を再試行したりできます。 - **Custom Webhook を構築する** [Build a custom webhook](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) handler to listen for events and build custom asynchronous payment flows. Test and debug your webhook integration locally with the Stripe CLI. - **構築済みアプリを導入する** パートナーアプリケーションを統合することで、[自動化](https://stripe.partners/?f_category=automation)や[マーケティング/セールス](https://stripe.partners/?f_category=marketing-and-sales)などの一般的なビジネスイベントを処理します。 ### Klarna 決済ページをカスタマイズする - **Klarna フォームを事前入力する** 顧客が延べ払いオプションを使用して Klarna に決済することを選択すると (後払い、分割払い、融資など)、Klarna は、リスク評価と承認のために十分な情報を収集します。情報の種類は、顧客の国によって異なります。ほとんどのヨーロッパの国では、完全な請求先住所と生年月日です。この情報は API を通じて渡すことができ、顧客がページに到着する前にフォームが事前入力されます。 ```curl curl https://api.stripe.com/v1/payment_intents \ -u "<>:" \ -d "payment_method_types[]=klarna" \ -d amount=1099 \ -d currency=eur \ -d confirm=true \ --data-urlencode "return_url=https://example.com/checkout/complete" \ -d "payment_method_data[type]=klarna" \ --data-urlencode "payment_method_data[billing_details][email]=customer@example.com" \ -d "payment_method_data[billing_details][name]=Jenny Rosen" \ --data-urlencode "payment_method_data[billing_details][phone]=+4915142321555" \ -d "payment_method_data[billing_details][address][line1]=Alexanderplatz 1" \ -d "payment_method_data[billing_details][address][city]=Berlin" \ -d "payment_method_data[billing_details][address][postal_code]=10551" \ -d "payment_method_data[billing_details][address][country]=DE" \ -d "payment_method_data[klarna][dob][day]=10" \ -d "payment_method_data[klarna][dob][month]=10" \ -d "payment_method_data[klarna][dob][year]=1990" ``` ![API からの請求詳細が事前入力され、英語で表示されるようにカスタマイズされた Klarna の支払いページのスクリーンショット](https://b.stripecdn.com/docs-statics-srv/assets/klarna-kpp-prefilled-customized.75932cc9aa3223960aa2fcf769c1ce62.png) Klarna の支払いページは、API からの請求書詳細が事前入力され、カスタマイズされてドイツの顧客に英語で表示されます。 ### PaymentIntent に項目を追加する > #### Klarna との統合項目 > > Klarna を導入する際に承認率を最適化するには、`line_items` データを含めて買い物客のカートの中身を表します。先行提供版については、[支払い項目](https://docs.stripe.com/payments/payment-line-items.md)をご覧ください。 ### ウェブサイトに決済手段のメッセージを表示する [Payment Method Messaging Element](https://docs.stripe.com/js/elements_object/create_element?type=paymentMethodMessaging) は、顧客が購入時に商品、カート、支払いの各ページから、利用できる後払いの決済オプションを直接確認できるようにする、埋め込み可能な UI コンポーネントです。 ウェブサイトに Payment Method Messaging Element を追加するには、[決済手段のメッセージを表示する](https://docs.stripe.com/elements/payment-method-messaging.md)をご覧ください。