Klarna による支払い方法を受け付ける
世界で普及している後払いの支払い方法である Klarna を受け付ける方法をご紹介します。
Unified line items with Klarna
To optimize approval rates when you integrate with Klarna, include line_
data to represent what’s in a shopper’s cart. For early access, see Payments line items.
顧客がアプリで Klarna を選択する際に、支払いを認証するための WebView が表示されます。顧客がアプリにリダイレクトされると、お客様は支払いが成功したか失敗したかをすぐに確認できます。
注
導入を開始する前に、支払い方法の設定からアカウントで Klarna が使用可能であることを確認してください。
Stripe を設定するサーバ側クライアント側
サーバ側
この組み込みには、Stripe API と通信するエンドポイントがサーバ上に必要です。Stripe の公式ライブラリを使用して、サーバから Stripe API にアクセスします。
クライアント側
React Native SDK はオープンソースであり、詳細なドキュメントが提供されています。内部では、ネイティブの iOS および Android の SDK を使用します。Stripe の React Native SDK をインストールするには、プロジェクトのディレクトリーで (使用するパッケージマネージャーによって異なる) 次のいずれかのコマンドを実行します。
次に、その他の必要な依存関係をインストールします。
- iOS の場合は、ios ディレクトリーに移動して
pod install
を実行し、必要なネイティブ依存関係もインストールします。 - Android の場合は、依存関係をインストールする必要はありません。
Stripe の初期化
React Native アプリで Stripe を初期化するには、決済画面を StripeProvider
コンポーネントでラップするか、initStripe
初期化メソッドを使用します。publishableKey
の API 公開可能キーのみが必要です。次の例は、StripeProvider
コンポーネントを使用して Stripe を初期化する方法を示しています。
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 ( <StripeProvider publishableKey={publishableKey} merchantIdentifier="merchant.identifier" // required for Apple Pay urlScheme="your-url-scheme" // required for 3D Secure and bank redirects > // Your app code here </StripeProvider> ); }
PaymentIntent を作成するサーバー側クライアント側
Stripe uses a PaymentIntent object to represent your intent to collect payment from a customer, tracking your charge attempts and payment state changes throughout the payment process.
サーバー側
First, create a PaymentIntent
on your server and specify the amount to collect and the currency. If you already have an integration using the Payment Intents API, add klarna
to the list of payment method types for your PaymentIntent
.
クライアント側
PaymentIntent には client secret が含まれています。これを React Native アプリで使用することで、PaymentIntent オブジェクト全体を渡すことなく安全に支払いプロセスを完了できます。アプリで、サーバーの PaymentIntent をリクエストし、その client secret を保存します。
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 <View>...</View>; }
Stripe に支払いを送信するクライアント側
Submitting the payment to Stripe requires the client secret from the PaymentIntent that you created. Include it in your call to confirmPayment
:
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 の組み込みをテストする
Below, we have specially selected test data for the currently supported customer countries. In a sandbox, Klarna approves or denies a transaction based on the supplied email address.
2 段階認証
6 桁の数字であれば、2 段階認証コードとして有効です。999999
を使用すると、認証は失敗します。
返済方法
Klarna のフロー内では、以下のテスト値を使用し、さまざまな返済方法を試すことができます。
タイプ | 値 |
---|---|
口座引き落とし | DE11520513735120710131 |
銀行振込 | デモの銀行 |
クレジットカード |
|
Debit Card |
|
失敗した支払い
Klarna は、取引を受け付けるか拒否するかを決定する際に複数の要因を考慮します (買い手が Klarna を使用している期間、顧客が返済する必要のある未払い額、現在の注文の金額など)。
When the customer selects a deferred payment method, Klarna performs a risk assessment before accepting the transaction. Klarna might decline the transaction due to unsatisfactory risk assessment result, the transaction amount involved, or the customer having a large outstanding debt. As such, we recommend that you present additional payment options such as card
in your checkout flow. In these cases, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions to requires_
.
Customers are expected to complete the payment within 48 hours after they’re redirected to the Klarna site. If no action is taken after 48 hours, the PaymentMethod is detached and the PaymentIntent object’s status automatically transitions from requires_
to requires_
.
このようなケースでは、決済フローに表示される別の支払いオプションで再試行するように顧客に通知します。
Klarna のレート制限
API requests to Klarna are subject to additional rate limits beyond Stripe’s API-wide rate limits. These limits can differ depending on the shape of the API requests that you make. In general, if you make more than around 360 requests per minute, you may see some rate limiting in the form of responses with HTTP status code 400
or 402
. Please contact us for more details if you’re concerned that your usage may reach these levels, as Klarna may be able to increase these limits on a case by case basis.
エラーメッセージ
Failed Klarna payments normally return one of the following failure codes. These codes show in the last_payment_error API object.
注意
Before the 2023-08-16
API version, every Klarna error reported as payment_intent_authentication_failure. Make sure your API version is up to date to see the detailed errors listed below.
エラーコード | 説明 |
---|---|
payment_method_customer_decline | 顧客が Klarna のページで購入をキャンセルしました |
payment_method_provider_decline | Klarna が顧客の支払いを拒否しました |
payment_intent_payment_attempt_expired | 顧客が Klarna のページで購入を完了しないまま、支払いセッションの有効期限が切れました |
payment_method_not_available | Klarna を使用しようとしたときに予期しないエラーが発生しました |