Boleto 支払い
ブラジルで一般的な支払い方法である Boleto を受け付ける方法をご紹介します。
ブラジルの Stripe ユーザーは、Payment Intents API および Payment Methods API を使用して、ブラジルの顧客から Boleto での支払いを受け付けることができます。顧客は ATM、銀行、オンラインバンクポータル、または公認の代理店のいずれかで、生成された番号が記載された Boleto の支払い票を使用して支払います。
PaymentIntent を作成するサーバ側
Stripe uses a PaymentIntent object to represent your intent to collect payment from a customer, tracking state changes from Boleto voucher creation to payment completion.
Create a PaymentIntent on your server with an amount and the brl
currency (Boleto does not support other currencies). If you already have an integration using the Payment Intents API, add boleto
to the list of payment method types for your PaymentIntent
.
Included in the returned PaymentIntent is a client secret, which you have to use to securely complete the payment process. Send the client secret back to the client so you can use it in later steps.
その他の支払い方法オプション
You can specify an optional expires_
parameter in the payment method options for your PaymentIntent
that sets the number of calendar days before a Boleto voucher expires. For example, if you create a Boleto voucher on Monday and you set expires_
to 2, the Boleto voucher will expire on Wednesday at 23:59 America/Sao_Paulo (UTC-3) time. If you set it to 0, the Boleto voucher will expire at the end of the day. The expires_
parameter can be set from 0 to 60 days. The default is 3 days. You can customize the default expiration days on your account in the Payment methods settings
支払い方法の詳細を収集するクライアント側
クライアントで支払いフォームを作成し、必要な請求先情報を顧客から収集します。
フィールド | 値 |
---|---|
name | 顧客の氏名。 |
email | 顧客のメールアドレス。 |
tax_ | 顧客の CPF (個人の場合) または CNPJ (ビジネスの場合)。CPF は 11 桁で、000. または 00000000000 の形式にする必要があります。CNPJ は 14 桁で、00. または 00000000000000 の形式にする必要があります。 |
address | 顧客の住所の町名と番地。 |
city | 顧客の住所の市区町村。 |
state | 顧客住所のブラジルの 2 文字の州 コード (ISO_3166-2:BR)。 |
postal_ | 顧客住所の郵便番号。郵便番号の形式は、XXXXX-XXX または XXXXXXXX にする必要があります。 |
注
name
、address
、city
のフィールドには、基本ラテン文字 (ASCII) ユニコードブロックの英数字を 1 文字以上含める必要があります。
<form id="payment-form"> <div class="form-row"> <label for="name"> Name </label> <input id="name" name="name" required> </div> <div class="form-row"> <label for="tax_id"> CPF/CNPJ </label> <input id="tax_id" name="tax_id" required> </div> <div class="form-row"> <label for="email"> Email </label> <input id="email" name="email" required> </div> <div class="form-row"> <label for="address"> Address </label> <input id="address" name="address" required> </div> <div class="form-row"> <label for="city"> City </label> <input id="city" name="city" required> </div> <div class="form-row"> <label for="state"> State </label> <input id="state" name="state" required> </div> <div class="form-row"> <label for="postal_code"> Postal Code </label> <input id="postal_code" name="postal_code" required> </div> <!-- Used to display form errors. --> <div id="error-message" role="alert"></div> <button id="submit-button">Pay with Boleto</button> </form>
Stripe に支払いを送信するクライアント側
When a customer clicks to pay with Boleto, use Stripe.js to submit the payment to Stripe. Stripe.js is our foundational JavaScript library for building payment flows.
Stripe.js スクリプトを決済ページに含めるには、このスクリプトを HTML ファイルの head
に追加します。
<head> <title>Checkout</title> <script src="https://js.stripe.com/v3/"></script> </head>
決済ページで以下の JavaScript を使用して、Stripe.js のインスタンスを作成します。
// Set your publishable key. Remember to switch to your live publishable key in production! // See your keys here: https://dashboard.stripe.com/apikeys const stripe = Stripe(
);'pk_test_TYooMQauvdEDq54NiTphI7jx'
Use stripe.confirmBoletoPayment and the client secret of the PaymentIntent
object that you created in Step 2 to submit the customer’s billing details.
確定されると、Stripe はモーダルを自動的に開き、顧客に Boleto の取引詳細を表示します。
var form = document.getElementById('payment-form'); form.addEventListener('submit', async (event) => { event.preventDefault(); const result = await stripe.confirmBoletoPayment( '{{PAYMENT_INTENT_CLIENT_SECRET}}', { payment_method: { boleto: { tax_id: document.getElementById('tax_id').value, }, billing_details: { name: document.getElementById('name').value, email: document.getElementById('email').value, address: { line1: document.getElementById('address').value, city: document.getElementById('city').value, state: document.getElementById('state').value, postal_code: document.getElementById('postal_code').value, country: 'BR', }, }, }, } ); // Stripe.js will open a modal to display the Boleto voucher to your customer // This async function finishes when the customer closes the modal if (result.error) { // Display error to your customer const errorMsg = document.getElementById('error-message'); errorMsg.innerText = result.error.message; } });
注
stripe.
の完了には数秒かかる場合があります。この間、フォームが再送信されないように無効化し、スピナーのような待機中のインジケータを表示します。エラーが発生した場合は、それを顧客に表示し、フォームを再度有効化し、待機中のインジケータを非表示にします。
Boleto の取引の詳細が正常に作成されると、返された PaymentIntent の status
プロパティの値が requires_
になります。ダッシュボードまたはオブジェクトのステータスプロパティを調べて、PaymentIntent のステータスを確認します。Boleto の取引の詳細が正常に作成されなかった場合は、返された error
を調べて原因を特定します (メールアドレス形式が無効であるなど)。
オプション: 顧客に取引の詳細へのリンクをメールで送信する
Stripe sends a payment_intent.requires_action event when a Boleto voucher is created successfully. If you need to email your customers the voucher link, you can locate the hosted_
in payment_intent.next_action.boleto_display_details.
オプション: 取引の詳細をカスタマイズする
Stripe では、ブランディング設定ページで、顧客に表示される UI をカスタマイズできます。
取引の詳細には、以下のブランド設定を適用できます。
- アイコン: ブランド画像と公開ビジネス名
- アクセント— 番号コピーボタンのカラーとして使用されます
- ブランドカラー: 背景色として使用されます
支払い後のイベントを処理するサーバ側
Boleto による支払いは非同期型であるため、売上はすぐには利用可能になりません。決済後、顧客が直ちに Boleto の支払いを行わないことがあります。
Stripe sends a payment_intent.succeeded event on the next business day (Monday through Friday excluding Brazilian holidays) for each Boleto voucher that was paid. Use the Dashboard or a custom webhook to receive these events and run actions (for example, sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow).
If a Boleto voucher is not paid before 23:59 America/Sao_Paulo (UTC-3) on the expiry date, Stripe sends a payment_intent.payment_failed event after 1 business day. For example, if a Boleto voucher expires on Thursday, the event is sent on Friday. If a Boleto voucher expires on Friday, the event is sent the following Monday.
イベント | 説明 | 次のステップ |
---|---|---|
payment_ | 顧客が有効期限前に Boleto の支払いを行いました。 | 顧客が購入した商品またはサービスのフルフィルメントを行います。 |
payment_ | 顧客が有効期限までに Boleto の支払いを行いませんでした。 | Contact the customer through email or push notification and request another payment method. |
組み込みをテストする
In a sandbox, set payment_
to the following values when you call stripe.confirmBoletoPayment to test different scenarios.
メールアドレス | 説明 |
---|---|
| 顧客が 3 分後に支払い、約 3 分後に 例: fulaninho@example.com |
| 顧客が即座に支払い、数秒以内に 例: succeed_immediately@example.com |
| 顧客が支払う前に期限切れになり、数秒以内に The 例: expire_immediately@example.com |
| 顧客が支払う前に期限切れになり、約 3 分後に The 例: expire_with_delay@example.com |
| Simulates a Boleto voucher which never succeeds; it expires according to the 例: fill_never@example.com |
納税者番号 | 説明 |
---|---|
CPF CNPJ | In a sandbox, set |
有効期限とキャンセル
Boleto バウチャーは expires_
UNIX タイムスタンプを過ぎると期限切れになり、顧客は有効期限が切れた Boleto バウチャーの支払いはできません。有効期限前に Boleto バウチャーをキャンセルすることはできません。
Boleto の有効期限が切れると、PaymentIntent のステータスは requires_
に変わります。この時点では、別の支払い方法を指定して PaymentIntent を確定するか、キャンセルすることができます。