#Bliss-firebase-samples

1 messages ยท Page 1 of 1 (latest)

stuck basin
#

Hi there ๐Ÿ‘‹ please bear with me a moment while I take a closer look.

#

Are you using the exact example that you linked, or did you use it as a reference to write your own approach?

lapis drift
#

A mixture, its a 1-to-1 copy of the function(s) in the sample but implemented in an already existing kotlin project.

stuck basin
#

Gotcha, would you mind sharing your relevant code snippets then?

lapis drift
#

Sure, give me a moment

#

I call the setupPaymentSession function here

override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        setupPaymentSession()
        _binding = FragmentInvestBinding.inflate(inflater, container, false)
        return binding.root
    }

The click listener is set here

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        observeClickedProject()
        binding.btnPaymentMethod.setOnClickListener {
          paymentSession.presentPaymentMethodSelection()
        }

And this is the function from the sample project

private fun setupPaymentSession () {
        // Setup Customer Session
        CustomerSession.initCustomerSession(requireContext(), FirebaseEphemeralKeyProvider())
        // Setup a payment session
        paymentSession = PaymentSession(this, PaymentSessionConfig.Builder()
            .setShippingInfoRequired(false)
            .setShippingMethodsRequired(false)
            .setBillingAddressFields(BillingAddressFields.None)
            .setShouldShowGooglePay(true)
            .build())

        paymentSession.init(
            object: PaymentSession.PaymentSessionListener {
                override fun onPaymentSessionDataChanged(data: PaymentSessionData) {
                    Log.d("PaymentSession", "PaymentSession has changed: $data")
                    Log.d("PaymentSession", "${data.isPaymentReadyToCharge} <> ${data.paymentMethod}")


                    if (data.isPaymentReadyToCharge) {
                        Log.d("PaymentSession", "Ready to charge");
                        binding.btnConfirm.isEnabled = true

                        data.paymentMethod?.let {
                            Log.d("PaymentSession", "PaymentMethod $it selected")
                            binding.tvCardConfirmation.text = "${it.card?.brand} card ends with ${it.card?.last4}"
                            selectedPaymentMethod = it
                        }
                    }
                }

                override fun onCommunicatingStateChanged(isCommunicating: Boolean) {
                    Log.d("PaymentSession",  "isCommunicating $isCommunicating")
                }

                override fun onError(errorCode: Int, errorMessage: String) {
                    Log.e("PaymentSession",  "onError: $errorCode, $errorMessage")
                }

            }
        )
    }
#

The ephemeralkeyprovider is the same file as the example project with the same cloud function as well

stuck basin
#

Gotcha, and you said the log was empty, so none of the log statements in the PaymentSessionListener are triggering?

lapis drift
#

The ones outside of the if statement do trigger,

2022-05-31 15:23:37.314 10505-10505/com.example.matchingcapitalapp D/PaymentSession: isCommunicating true
2022-05-31 15:23:37.314 10505-10505/com.example.matchingcapitalapp D/PaymentSession: PaymentSession has changed: PaymentSessionData(isShippingInfoRequired=false, isShippingMethodRequired=false, cartTotal=0, shippingTotal=0, shippingInformation=null, shippingMethod=null, paymentMethod=null, useGooglePay=false)
2022-05-31 15:23:37.314 10505-10505/com.example.matchingcapitalapp D/PaymentSession: false <> null

And a bit after it'll create 2 ephemeral keys (Im not sure if its okay to send those in public, even when using a testkey?)
and it'll log the isCommunicating false

Those appear when the view itself is created, but when the button to choose a payment method with presentPaymentMethodSelection() is clicked, none of the log statements appear

rustic pier
#

Do you have any idea where isPaymentReadyToCharge is coming from? It doesn't appear anywhere else in that repository.

#

And yea looking into why two ephemeral keys are being created is a good debugging path -- i wouldn't expect this

lapis drift
#

It comes from PaymentSessionData.kt from package com.stripe.android

rustic pier
#

Gotcha ok and any ideas why you end up generating to ephemeral keys?

lapis drift
#

Honestly I've tried debugging it but it doesn't make sense to me either

#

The function is only called in setupPaymentSession() in initCustomerSession, but the setup is only called in onCreateView()

#

But I only get 2 ephemeral keys but any of the logs relating to the code below in the same function only trigger a singular time, so it doesn't seem to run any of those twice

#

There's also only 1 cloud function with createEphemeralKey so its not that its calling 2 different cloud functions

rustic pier
#

If you're familiar with firebase functionality and how it works with Android (I am not), I'd probably discourage referring to this sample app. I think you'd likely be better off building your own firebase integration starting from the modern Android example we have in that repository.

#

It's build for a more traditional client/server set up, but should be possible to adapt to your needs

#

(None of our samples are meant to be used as production code, so you'd need to customize this anyway)

lapis drift
#

Yeah, its for a school project but this seemed like a pretty quick way to use the extension

#

Well I say school project but its more my curiousity outside of the actual scope

rustic pier
#

It's good to explore! ๐Ÿ˜„

lapis drift
#

But I'll try that in a new branch and see where I get, I might come back to bother again :P

rustic pier
#

Alright, but like i said I'd suggest trying the traditional app+server pattern instead of firebase here, unless thats a specific requirement/goal

#

in which case i think building your own up from small pieces will be better for learning anyways, instead of trying to figure out whats not working in this sample

#

Once you tackle that from first principles, then maybe you'll be able to debug this one

lapis drift
#

Yeah firebase was at the teachers recommendation since setting up our own backend falls outside of the course scope

#

I'd consider swapping to Springboot since I've used it before if we had more time ^^

rustic pier
#

The payment sheet example i shared above uses a pre-existing example server on glitch

#

So it works out of the box

#

or you can remix (fork) on glitch and use your own API keys to start customizing

lapis drift
#

Is it safe to assume that implementing stripe with glitch either the pre-existing sample server or our own would work fine with firebase also being present?

rustic pier
#

Sure, yea you could weave that in in parallel if you wanted

#

you've have to remix the example glitch to customize the backend