(async()=>{const response =awaitfetch('/secret');const{client_secret: clientSecret}=await response.json();// Render the form using the clientSecret})();
// Set your publishable key. Remember to change this to your live publishable key in production!// See your keys here: https://dashboard.stripe.com/apikeysconst stripe =Stripe(
const form = document.getElementById('setup-form');
form.addEventListener('submit',function(event){
event.preventDefault();// Set the clientSecret here
stripe.confirmCashappSetup(
clientSecret,{
payment_method:{
type:'cashapp',},
return_url:'https://www.example.com/checkout/done',},);});
顧客は、モバイルアプリまたはデスクトップアプリで Cash App Pay を認証することができます。confirmCashappSetup を呼び出した後、顧客が使用するクライアントは、モバイルの場合はリダイレクト、デスクトップの場合は QR コードなど、認証方法を決定します。認証のレスポンスには、次のステップで PaymentIntent を作成するために使用する必要がある支払い方法 ID も含まれています。
const form = document.getElementById('payment-form');
form.addEventListener('submit',function(event){
event.preventDefault();// Set the clientSecret here you got in Step 2
stripe.confirmCashappSetup(
clientSecret,{
payment_method:{
type:'cashapp',},
return_url:'https://www.example.com/checkout/done',},{
handleActions:false},).then((result)=>{if(result.error){// Display error to your customer.}elseif(result.paymentIntent.status==="requires_action"){const nextAction = result.setupIntent.next_action.cashapp_handle_redirect_or_display_qr_code;const expiresAt = nextAction.qr_code.expires_at;if(IS_MOBILE){// This URL redirects the customer to Cash App to approve or decline the payment.const mobileAuthUrl = nextAction.mobile_auth_url;}elseif(IS_DESKTOP){// Render the QR code and display it to the customer using the below image source.const imageUrlSvg = nextAction.qr_code.image_url_svg;const imageUrlPng = nextAction.qr_code.image_url_png;}}});});