# Accept a payment with Revolut Pay Add support for Revolut Pay to your integration. # Direct API Revolut Pay is a [reusable](https://docs.stripe.com/payments/payment-methods.md#usage) payment method where customers are required to [authenticate](https://docs.stripe.com/payments/payment-methods.md#customer-actions) their payment. Customers pay by being redirected from your website or app, authorizing the payment with Revolut Pay, then returning to your website or app. You get [immediate notification](https://docs.stripe.com/payments/payment-methods.md#payment-notification) of whether the payment succeeded or failed. ## Siapkan Stripe [Sisi server] Pertama, Anda membutuhkan akun Stripe. [Daftar sekarang](https://dashboard.stripe.com/register). Gunakan pustaka resmi kami untuk mendapatkan akses ke API Stripe dari aplikasi Anda: #### 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' ``` ## Buat PaymentIntent [Sisi server] A [PaymentIntent](https://docs.stripe.com/api/payment_intents/object.md) is an object that represents your intent to collect payment from your customer and tracks the lifecycle of the payment process. Create a `PaymentIntent` on your server and specify the amount to collect and a [supported currency](https://docs.stripe.com/payments/revolut-pay.md#supported-currencies). If you have an existing [Payment Intents](https://docs.stripe.com/payments/payment-intents.md) integration, add `revolut_pay` to the list of [payment method types](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[]=revolut_pay" \ -d amount=1099 \ -d currency=gbp ``` ### Ambil client secret PaymentIntent menyertakan *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)) yang digunakan pada sisi client untuk menyelesaian proses pembayaran dengan aman. Anda dapat menggunakan pendekatan berbeda untuk meneruskan client secret ke sisi client. #### Aplikasi halaman tunggal Ambil client secret dari endpoint pada server Anda, menggunakan fungsi `fetch` browser. Pendekatan ini paling baik jika sisi client Anda adalah aplikasi satu halaman, terutama yang dibangun dengan kerangka kerja frontend modern seperti React. Buat endpoint server yang melayani client secret: #### Ruby ```ruby get '/secret' do intent = # ... Create or retrieve the PaymentIntent {client_secret: intent.client_secret}.to_json end ``` Kemudian ambil client secret dengan JavaScript pada sisi client: ```javascript (async () => { const response = await fetch('/secret'); const {client_secret: clientSecret} = await response.json(); // Render the form using the clientSecret })(); ``` #### Rendering sisi server Teruskan client secret ke client dari server Anda. Pendekatan ini berfungsi paling baik jika aplikasi menghasilkan konten statis pada server sebelum mengirimkannya ke browser. Tambahkan [client_secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) di formulir checkout Anda. Di kode sisi server Anda, ambil client secret dari PaymentIntent: #### Ruby ```erb
``` ```ruby get '/checkout' do @intent = # ... Fetch or create the PaymentIntent erb :checkout end ``` ## Redirect to the Revolut Pay wallet [Sisi klien] Bila pelanggan mengklik untuk membayar dengan Revolut Pay, gunakan Stripe.js untuk menyerahkan pembayaran kepada Stripe. [Stripe.js](https://docs.stripe.com/payments/elements.md) adalah pustaka dasar JavaScript untuk membangun alur pembayaran. Ini menangani kompleksitas secara otomatis seperti pengarah ulang yang dijelaskan di bawah, dan memungkinkan Anda memperluas integrasi ke metode pembayaran lain. Sertakan skrip Stripe.js di halaman checkout dengan menambahkannya ke `head` file HTML Anda. ```html Checkout ``` Buat instance Stripe.js dengan JavaScript berikut di halaman checkout Anda. ```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 const stripe = Stripe('<>'); ``` Use the [client secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) of the `PaymentIntent` and call `stripe.confirmPayment` to handle the Revolut Pay redirect. Add a `return_url` to determine where Stripe redirects the customer after they complete the payment. ```javascript const form = document.getElementById('payment-form'); form.addEventListener('submit', async function(event) { event.preventDefault(); // Set the clientSecret of the PaymentIntent const { error } = await stripe.confirmPayment({ clientSecret: clientSecret, confirmParams: { payment_method_data: { type: 'revolut_pay', }, // Return URL where the customer should be redirected after the authorization return_url: `${window.location.href}`, }, }); if (error) { // Inform the customer that there was an error. const errorElement = document.getElementById('error-message'); errorElement.textContent = result.error.message; } }); ``` `return_url` sesuai dengan halaman di situs web Anda yang menampilkan hasil pembayaran. Anda dapat menentukan apa yang akan ditampilkan dengan [memverifikasi status](https://docs.stripe.com/payments/payment-intents/verifying-status.md#checking-status) `PaymentIntent`. Untuk memverifikasi status, pengalihan Stripe ke `return_url` menyertakan parameter query URL berikut. Anda juga dapat menambahkan parameter query sendiri ke `return_url`. Parameter tersebut tetap ada selama proses pengalihan. | Parameter | Keterangan | | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | | `payment_intent` | Identifier unik untuk `PaymentIntent`. | | `payment_intent_client_secret` | [Client secret](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-client_secret) dari objek `PaymentIntent`. | ## Optional: Tangani pengalihan secara manual [Sisi server] The best way to handle redirects is to use Stripe.js with `confirmPayment`. If you need to manually redirect your customers: 1. Berikan URL untuk mengalihkan pelanggan Anda setelah mereka menyelesaikan pembayaran. ```curl curl https://api.stripe.com/v1/payment_intents/pi_1DRuHnHgsMRlo4MtwuIAUe6u/confirm \ -u "<>:" \ -d payment_method=pm_1EnPf7AfTbPYpBIFLxIc8SD9 \ --data-urlencode "return_url=https://shop.example.com/crtA6B28E1" ``` 1. Confirm the `PaymentIntent` has a status of `requires_action`. The type for the `next_action` will be [redirect_to_url](https://docs.stripe.com/api/payment_intents/object.md#payment_intent_object-next_action-redirect_to_url). ```json "next_action": { "type": "redirect_to_url", "redirect_to_url": { "url": "https://hooks.stripe.com/...", "return_url": "https://example.com/checkout/complete" } } ``` 1. Alihkan pelanggan ke URL yang diberikan di properti `next_action`. Bila pelanggan menyelesaikan proses pembayaran, mereka akan dikirim ke tujuan `return_url`. Parameter query URL `payment_intent` dan `payment_intent_client_secret` disertakan dan Anda dapat mengirim langsung parameter query sendiri, sebagaimana dijelaskan di atas. ## Optional: Tangani kejadian pascapembayaran Stripe mengirim kejadian [payment_intent.succeeded](https://docs.stripe.com/api/events/types.md#event_types-payment_intent.succeeded) ketika selesai pembayaran. Gunakan Dashboard, *webhook* (A webhook is a real-time push notification sent to your application as a JSON payload through HTTPS requests) custom, atau solusi mitra untuk menerima kejadian ini dan menjalankan tindakan, seperti mengirim email konfirmasi pesanan kepada pelanggan Anda, mencatat penjualan di database, atau memulai alur kerja pengiriman. Mendengarkan kejadian ini daripada menunggu callback dari client. Di client, pelanggan dapat menutup jendela browser atau keluar dari aplikasi sebelum callback mengeksekusi, dan client jahat dapat memanipulasi respons. Penyiapan integrasi untuk mendengarkan kejadian asinkron juga membantu Anda menerima lebih banyak metode pembayaran di masa mendatang. Pelajari tentang [perbedaan antara semua metode pembayaran yang didukung](https://stripe.com/payments/payment-methods-guide). ### Terima kejadian dan jalankan tindakan bisnis Ada beberapa opsi untuk menerima dan menjalankan tindakan bisnis. #### Secara manual Gunakan Dashboard Stripe untuk melihat semua pembayaran Stripe Anda, mengirim resi email, menangani payout, atau mencoba kembali pembayaran yang gagal. - [Lihat pembayaran percobaan Anda di Dashboard](https://dashboard.stripe.com/test/payments) #### Kode custom Bangun handler webhook untuk mendengarkan kejadian dan buat alur pembayaran asinkron custom. Coba dan debug integrasi webhook Anda secara lokal dengan Stripe CLI. - [Buat webhook kustom](https://docs.stripe.com/webhooks/handling-payment-events.md#build-your-own-webhook) #### Aplikasi siap-rakit Tangani kejadian bisnis umum, seperti [otomatisasi](https://stripe.partners/?f_category=automation) atau [pemasaran dan penjualan](https://stripe.partners/?f_category=marketing-and-sales), dengan mengintegrasikan aplikasi mitra. ## Mata uang yang didukung You can create Revolut Pay payments in the currencies that map to your country. Currently, we support `gbp`, `eur`, `ron`, `huf`, `pln`, and `dkk`. The default local currency for Revolut Pay UK customers is `gbp` and for other EU customers it’s `eur`. | Mata uang | Negara | | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `gbp` | Inggris | | `eur`, `ron`, `huf`, `pln`, `dkk` | Austria, Belgium, Bulgaria, Croatia, Cyprus, Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Ireland, Italy, Latvia, Liechtenstein, Lithuania, Luxembourg, Malta, Netherlands, Norway, Poland, Portugal, Romania, Slovakia, Slovenia, Spain, Sweden |