Stripe API – How to display apple pay only on PaymentElement

In my application I have flow where user needs to add payment method and then it’s charged later in future.

So basically what I’m doing is that frontend is pinging aplication backend to create stripe setup_intent:

 def setup_intent
    if current_account.stripe_id.blank?
      render json: { data: nil, status: 'No customer ID found' }, status: :not_found
      return
    end

    options = {
      customer: current_account.stripe_id,
    }

    if params[:payment_method_type].present?
      options[:payment_method_types] = [params[:payment_method_type]]
    else
      options[:automatic_payment_methods] =  { enabled: true }
    end

    setup_intent = Stripe::SetupIntent.create(options)

    data = {
      client_secret: setup_intent.client_secret,
      id: setup_intent.id,
    }

    render json: { data: data, status: "success" }, status: :ok
  rescue Stripe::StripeError => e
    render json: { data: nil, status: "Error: #{e.message}" }, status: :unprocessable_entity
  end

With backend response frontend get client_secret which is then used to create PaymentElement available in stripe.js:

        fetch('http://localhost:3000/api/v2/payment_methods/setup_intent', {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${bearerToken}`
            }
        })
        .then(response => response.json())
        .then(response => {
            const elements = stripe.elements({
                clientSecret: response.data.client_secret,
                loader: 'auto',
            });

            // https://docs.stripe.com/js/elements_object/create_payment_element
            const paymentElement = elements.create("payment", {
                layout: "auto",
            });

            paymentElement.mount('#payment');

            document.getElementById('submit').addEventListener('click', async function(event) {
                // https://docs.stripe.com/js/setup_intents/confirm_card_setup
                const response = await stripe?.confirmSetup({
                    elements,
                    redirect: 'if_required',
                    confirmParams: {
                        return_url: 'http://localhost:3000',
                    },
                });

                if (!!response?.error) {
                    alert(response.error.message);
                    return;
                }
            })
        });

Thing is that on one screen of my application I need PaymentElement which will save only card as payment options and on another one only paypal and on one only apple pay. Everyting is working fine for card and paypal but I’m stuck with apple pay.

For example when I want to display only card in PaymentElement I’m using following url:

http://localhost:3000/api/v2/payment_methods/setup_intent?payment_method_type=card

and for paypal:

http://localhost:3000/api/v2/payment_methods/setup_intent?payment_method_type=paypal

But when I want to display apple pay:

http://localhost:3000/api/v2/payment_methods/setup_intent?payment_method_type=apple_pay

I got error:

{
    "data": null,
    "status": "Error: The payment method type "apple_pay" is invalid. See https://stripe.com/docs/api/setup_intents/create#create_setup_intent-payment_method_types for the full list of supported payment method types. Please also ensure the provided types are activated in your dashboard (https://dashboard.stripe.com/account/payments/settings) and your account is enabled for any features that you are trying to use."
}

If I don’t send payment_method_type query string to route, backend will create setup_intent with automatic_payment_methods: {enabled: true} and initiating PaymentElement with that client_secret apple pay is showing fine.

enter image description here

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật