Lewati ke konten
Buat akun atau Masuk
Logo Dokumen Stripe
/
Tanya AI
Buat akunMasuk
Mulai
Pembayaran
Pendapatan
Platform dan situs belanja online
Manajemen uang
Sumber daya pengembang
API & SDKBantuan
Gambaran UmumTerima pembayaranUpgrade integrasi Anda
Pembayaran online
Gambaran umumTemukan contoh penggunaan Anda
Gunakan Payment Links
Gunakan halaman checkout bawaan
Buat integrasi kustom dengan Elements
    Gambaran umum
    Panduan mulai cepat
    Stripe Elements
    Bandingkan Checkout Sessions dan PaymentIntents
    Rancang integrasi lanjutan
    Sesuaikan tampilan dan nuansa
    Kelola metode pembayaran
    Kumpulkan informasi tambahan
    Bangun integrasi langganan
    Pembaruan dinamis
    Tambahkan diskon
    Pungut pajak atas pembayaran Anda
    Menukarkan kredit
    Mungkinkan pelanggan membayar dalam mata uang lokal
    Simpan dan ambil metode pembayaran pelanggan
      Simpan metode pembayaran yang digunakan untuk pembayaran
      Simpan metode pembayaran tanpa melakukan pembayaran
    Kirim resi dan invoice yang telah dibayar
    Setujui pembayaran di server Anda secara manual
    Otorisasikan dan tarik pembayaran secara terpisah
    Log perubahan Elements dengan Checkout Sessions API beta
Bangun integrasi dalam aplikasi
Gunakan Managed Payments
Pembayaran rutin
Pembayaran di tempat
Terminal
Metode Pembayaran
Tambahkan metode pembayaran
Kelola metode pembayaran
Checkout lebih cepat dengan Link
Operasi pembayaran
Analitik
Saldo dan waktu pelunasan
Kepatuhan dan keamanan
Mata uang
Penolakan
Sengketa
Pencegahan penipuan
Perlindungan penipuan Radar
Payout
ResiPengembalian dana dan pembatalan
Integrasi lanjutan
Alur pembayaran custom
Akuisisi fleksibel
Pembayaran di Luar Sesi
Orkestrasi multi-pemroses
Di luar pembayaran
Dirikan perusahaan Anda
Kripto
Perdagangan agen
Pembayaran mesin
Financial Connections
Climate
Verifikasikan identitas
Amerika Serikat
Bahasa Indonesia
BerandaPembayaranBuild a custom integration with ElementsSave and retrieve customer payment methods

Simpan metode pembayaran pelanggan bila mereka menggunakannya untuk pembayaran

Pelajari cara menyimpan metode pembayaran pelanggan saat Anda mengonfirmasi PaymentIntent.

Use the Checkout Sessions API to save payment details during a purchase. This is useful for situations such as:

  • Charging a customer for an e-commerce order and storing the payment details for future purchases.
  • Initiating the first payment in a series of recurring payments.
  • Charging a deposit and storing the payment details to charge the full amount later.

Compliance

Anda bertanggung jawab untuk mematuhi semua hukum, peraturan, dan aturan jaringan yang berlaku saat menyimpan detail pembayaran pelanggan untuk penggunaan di masa mendatang, seperti menampilkan metode pembayaran pelanggan kepada mereka dalam proses alur checkout untuk pembelian di masa mendatang atau menagih mereka saat mereka tidak aktif menggunakan situs web atau aplikasi Anda. Sebelum menyimpan atau menagih metode pembayaran pelanggan, pastikan Anda:

  • Tambahkan ketentuan ke situs atau aplikasi Anda yang menyatakan bagaimana Anda berencana menyimpan detail metode pembayaran, seperti:
    • Perjanjian pelanggan yang memungkinkan Anda untuk memulai pembayaran atau serangkaian pembayaran atas nama mereka untuk transaksi tertentu.
    • Waktu dan frekuensi pembayaran yang diantisipasi (misalnya, jika charge untuk angsuran terjadwal, pembayaran langganan, atau penambahan saldo tidak terjadwal).
    • Cara Anda menentukan jumlah pembayaran.
    • Kebijakan pembatalan Anda, jika metode pembayarannya untuk layanan langganan.
  • Gunakan metode pembayaran tersimpan hanya untuk tujuan yang tercantum dalam ketentuan Anda.
  • Kumpulkan persetujuan eksplisit dari pelanggan untuk penggunaan khusus ini. Misalnya, sertakan kotak centang "Simpan metode pembayaran saya untuk di masa mendatang.
  • Catat perjanjian tertulis pelanggan Anda terhadap ketentuan Anda.

Catatan

When using Elements with the Checkout Sessions API, only cards are supported for saved payment methods. You can’t save other payment methods, such as bank accounts.

Prerequisites

  1. Follow the Checkout guide to accept a payment.
  2. Follow this guide to save the payment method used during a payment so you can retrieve it for use in future payments by the same customer.

Enable saved payment methods

Peringatan

Global privacy laws are complicated and nuanced. Before implementing the ability to store customer payment method details, work with your legal team to make sure that it complies with your privacy and compliance framework.

To allow a customer to save their payment method for future use, specify the saved_payment_method_options.payment_method_save parameter when creating the Checkout Session.

Saving a payment method requires a Customer. Pass an existing customer or create a new one by setting customer_creation to always on the Checkout Session.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/checkout/sessions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d "line_items[0][price]"=
"{{PRICE_ID}}"
\ -d "line_items[0][quantity]"=2 \ -d mode=payment \ -d ui_mode=custom \ -d customer_creation=always \ -d "saved_payment_method_options[payment_method_save]"=enabled

After you create the Checkout Session, use the client secret returned in the response to build your checkout page.

Catatan

In the latest version of Stripe.js, specifying enableSave to auto is optional because that’s the default value when saved payment methods are enabled on the Checkout Session.

The Payment Element automatically displays a consent collection checkbox when saved payment methods are enabled on the Checkout Session. You can explicitly configure this behavior using elementsOptions on initCheckout.

checkout.js
const checkout = stripe.initCheckout({ clientSecret, elementsOptions: { savedPaymentMethod: { // Default is 'auto' in the latest version of Stripe.js - this configuration is optional enableSave: 'auto', } } });

Reuse a previously saved payment method

Each saved payment method is linked to a Customer object. Before creating the Checkout Session, authenticate your customer, and pass the corresponding Customer ID to the Checkout Session.

Catatan

In the latest version of Stripe.js, enableRedisplay defaults to auto when saved payment methods are enabled on the Checkout Session.

The Payment Element automatically redisplays previously saved payment methods for your customer to use during checkout when saved payment methods are enabled on the Checkout Session.

Command Line
cURL
Stripe CLI
Ruby
Python
PHP
Java
Node.js
Go
.NET
No results
curl https://api.stripe.com/v1/checkout/sessions \ -u "
sk_test_BQokikJOvBiI2HlWgH4olfQ2
:"
\ -d "line_items[0][price]"=
"{{PRICE_ID}}"
\ -d "line_items[0][quantity]"=2 \ -d mode=payment \ -d ui_mode=custom \ -d customer=
"{{CUSTOMER_ID}}"

You can explicitly configure the redisplay behavior using elementsOptions on initCheckout.

checkout.js
const checkout = stripe.initCheckout({ clientSecret, elementsOptions: { savedPaymentMethod: { // Default is 'auto' in the latest version of Stripe.js - this configuration is optional enableSave: 'auto', // Default is 'auto' in the latest version of Stripe.js - this configuration is optional enableRedisplay: 'auto', } } });

OpsionalBuild a saved payment method UI

You can build your own saved payment method UI instead of using the built-in UI provided by the Payment Element.

To prevent the Payment Element from handling consent collection and displaying the previously saved payment methods, pass in additional elementsOptions on initCheckout.

checkout.js
const checkout = stripe.initCheckout({ clientSecret, elementsOptions: { savedPaymentMethod: { enableSave: 'never', enableRedisplay: 'never', } } });

Collect consent

Peringatan

Global privacy laws are complicated and nuanced. Before implementing the ability to store customer payment method details, work with your legal team to make sure that it complies with your privacy and compliance framework.

In most cases, you must collect a customer’s consent before you save their payment method details. The following example shows how to obtain consent using a checkbox.

index.html
<label> <input type="checkbox" id="save-payment-method-checkbox" /> Save my payment information for future purchases </label> <button id="pay-button">Pay</button> <div id="confirm-errors"></div>

When you call confirm, you can indicate to Stripe that your customer has provided consent by passing the savePaymentMethod parameter. When you save a customer’s payment details, you’re responsible for complying with all applicable laws, regulations, and network rules.

checkout.js
const checkout = stripe.initCheckout({clientSecret}); const button = document.getElementById('pay-button'); const errors = document.getElementById('confirm-errors'); const checkbox = document.getElementById('save-payment-method-checkbox'); const loadActionsResult = await checkout.loadActions(); if (loadActionsResult.type === 'success') { const {actions} = loadActionsResult; button.addEventListener('click', () => { // Clear any validation errors errors.textContent = ''; const savePaymentMethod = checkbox.checked; actions.confirm({savePaymentMethod}).then((result) => { if (result.type === 'error') { errors.textContent = result.error.message; } }); }); }

Render saved payment methods

Use the savedPaymentMethods array on the front end to render the customer’s available payment methods.

Catatan

The savedPaymentMethods array includes only the payment methods that have allow_redisplay set to always. Follow the steps for collecting consent from your customer and make sure to properly set the allow_redisplay parameter.

index.html
<div id="saved-payment-methods"></div>
checkout.js
const checkout = stripe.initCheckout({clientSecret}); const loadActionsResult = await checkout.loadActions(); if (loadActionsResult.type === 'success') { const container = document.getElementById('saved-payment-methods'); const {actions} = loadActionsResult; actions.getSession().savedPaymentMethods.forEach((pm) => { const label = document.createElement('label'); const radio = document.createElement('input'); radio.type = 'radio'; radio.value = pm.id; label.appendChild(radio); label.appendChild(document.createTextNode(`Card ending in ${pm.card.last4}`)); container.appendChild(label); }); }

Confirm with a saved payment method

When your customer selects a saved payment method and is ready to complete checkout, call confirm and pass in the paymentMethod ID.

index.html
<button id="pay-button">Pay</button>
checkout.js
const checkout = stripe.initCheckout({clientSecret}); const loadActionsResult = await checkout.loadActions(); if (loadActionsResult.type === 'success') { const container = document.getElementById('saved-payment-methods'); const {actions} = loadActionsResult; actions.getSession().savedPaymentMethods.forEach((pm) => { const label = document.createElement('label'); const radio = document.createElement('input'); radio.type = 'radio'; radio.value = pm.id; label.appendChild(radio); label.appendChild(document.createTextNode(`Card ending in ${pm.card.last4}`)); container.appendChild(label); }); }
Apakah halaman ini membantu?
YaTidak
  • Butuh bantuan? Hubungi Tim CS.
  • Mengobrol dengan pengembang Stripe di Discord.
  • Lihat log perubahan kami.
  • Ada pertanyaan? Hubungi Bagian Penjualan.
  • LLM? Baca llms.txt.
  • Dijalankan oleh Markdoc