#Stripe API checkout/Web form input credit card/setup mode/#Ruby example
# Docs
# https://stripe.com/docs/payments/checkout/collecting
# Code
require 'stripe'
Stripe::api_key = ENV['STRIPE_SECRET_KEY']
checkout_session = Stripe::Checkout::Session.create(
payment_method_types: ["card"],
mode: "setup",
# customer_email: "",
# client_reference_id: "",
success_url: "http://example.com",
cancel_url: "http://example.com",
)
# customer = Stripe::Customer.create
#
# checkout_session = Stripe::Checkout::Session.create(
# payment_method_types: ["card"],
# mode: "setup",
# customer: customer.id
# success_url: "http://example.com",
# cancel_url: "http://example.com",
# )
# Exception: Stripe::InvalidRequestError: You can not pass a `customer` in setup mode.
puts checkout_session
# e.g
#
# {
# "id": "cs_test_nSeAmaYPHYg3uYoJr0AGc8KDPWLX2SnW5ESdiSiNpIwkwb7QjoLBdcUZ",
# "object": "checkout.session",
# "billing_address_collection": null,
# "cancel_url": "http://example.com",
# "client_reference_id": null,
# "customer": null,
# "customer_email": null,
# "display_items": [
# ],
# "livemode": false,
# "locale": null,
# "metadata": {
# },
# "mode": "setup",
# "payment_intent": null,
# "payment_method_types": [
# "card"
# ],
# "setup_intent": "seti_1GDl7YCmti5jpytU0I0ByfjD",
# "submit_type": null,
# "subscription": null,
# "success_url": "http://example.com"
# }
puts <<~HTML
<script src="https://js.stripe.com/v3/"></script>
<script>
var stripe = Stripe('#{ENV['STRIPE_PUBLIC_KEY']}');
stripe.redirectToCheckout({
// Make the id field from the Checkout Session creation API response
// available to this file, so you can provide it as parameter here
// instead of the placeholder.
sessionId: '#{checkout_session.id}'
}).then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
});
</script>
HTML
# e.g
#
# Save this html file in your machine and access
#
# <script src="https://js.stripe.com/v3/"></script>
#
# <script>
#
# var stripe = Stripe('pk_test_wxxxxxxxxxxxxxxxxxxxxxx');
#
# stripe.redirectToCheckout({
# // Make the id field from the Checkout Session creation API response
# // available to this file, so you can provide it as parameter here
# // instead of the placeholder.
# sessionId: 'cs_test_nSeAmaYPHYg3uYoJr0AGc8KDPWLX2SnW5ESdiSiNpIwkwb7QjoLBdcUZ'
# }).then(function (result) {
# // If `redirectToCheckout` fails due to a browser or network
# // error, display the localized error message to your customer
# // using `result.error.message`.
# });
#
# </script>
# Redirect to URL example
# https://checkout.stripe.com/pay/cs_test_fRmOtv2TQjhfo1WmVXCxw68tlckFz6KiIUi2EwvHTACynBckPrfu98L1#fidkdWxOYHwnPyd1blpxYHZxWnJhVDRvd1B3bHRzY2xWSF9ycUJAUVFfZzU1dU9tNkJRTTMnKSd3YGNgd3dgd0p3bGJsayc%2Fa3BpaSknaGxhdic%2FfidicGxhJz8nS0QnKSdocGxhJz8nYzRhMWNnPDQoMGc1NygxPWNmKGc0PDUoNGRjMGFnPTQwMWQwJykndmxhJz8nNTNnMTcxZDMoNzE2MCgxMzwwKDwzY2coYTZgYzM0MjM1ZDU1J3gpJ2dgcWR2Jz9eWHgl
# After checkout
Stripe::Checkout::Session.retrieve(id: checkout_session.id, expand: ["setup_intent", "setup_intent.payment_method"]).setup_intent
# There is payment method
# => #<Stripe::SetupIntent:0x3fc716e16f00 id=seti_1GDlGfCmti5jpytUDumoV2O4> JSON: {
# "id": "seti_1GDlGfCmti5jpytUDumoV2O4",
# "object": "setup_intent",
# "application": null,
# "cancellation_reason": null,
# "client_secret": "seti_xxxxxxxxxxxxxxxxxxxxxxxxxx",
# "created": 1582090721,
# "customer": null,
# "description": null,
# "last_setup_error": null,
# "livemode": false,
# "mandate": null,
# "metadata": {},
# "next_action": null,
# "on_behalf_of": null,
# "payment_method": {"id":"pm_1GDlLxCmti5jpytUaLbokfjU","object":"payment_method","billing_details":{"address":{"city":null,"country":"JP","line1":null,"line2":null,"postal_code":null,"state":null},"email":"[email protected]","name":"yuma inaura","phone":null},"card":{"brand":"visa","checks":{"address_line1_check":null,"address_postal_code_check":null,"cvc_check":"pass"},"country":"US","exp_month":11,"exp_year":2030,"fingerprint":"3Dnj9E30BUfyFTcl","funding":"credit","generated_from":null,"last4":"4242","three_d_secure_usage":{"supported":true},"wallet":null},"created":1582091050,"customer":null,"livemode":false,"metadata":{},"type":"card"},
# "payment_method_options": {"card":{"request_three_d_secure":"automatic"}},
# "payment_method_types": [
# "card"
# ],
# "single_use_mandate": null,
# "status": "succeeded",
# "usage": "off_session"
# }
succeeded and redirect to
JP
Stripe API API를 사용하여 WebForm에서 결제 정보 및 카드 정보를 등록하기위한 세션 발급
Original by Github issue
Reference
이 문제에 관하여(#Stripe API checkout/Web form input credit card/setup mode/#Ruby example), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/YumaInaura/items/71cdd3dc26d3bb30f15d
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(#Stripe API checkout/Web form input credit card/setup mode/#Ruby example), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/YumaInaura/items/71cdd3dc26d3bb30f15d텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)