【问题标题】:Use the Same Cloud Function in Android as I do in iOS While Creating a Stripe Customer在创建 Stripe 客户时,在 Android 中使用与在 iOS 中相同的云功能
【发布时间】:2021-12-26 03:31:18
【问题描述】:

当客户像在我的 iOS 应用上一样在我的 Android 应用上注册新帐户时,我正在尝试创建一个 stripeID。我的问题是 - 是否可以使用相同的 Cloud Function 在我的 Android 应用程序中创建 Stripe Customer,或者我是否需要为 Android 创建一个全新的 Functions 文件夹?谢谢!

云功能

exports.createStripeCustomer = functions.https.onCall( async (data, context) => {

    const email = data.email
    const uid = context.auth.uid
    console.log(uid)

    if (uid === null) {
      console.log('Illegal access attempt due to unauthenticated attempt.')
      throw new functions.https.HttpsError('internal', 'Illegal access attempt')
    }

    return stripe.customers
    .create({ email: email })
    .then((customer) => {
      return customer["id"];
    })
    .then((customerId) => {
      admin.database().ref("customers").child(uid).update({
        stripeId: customerId,
        email: email,
        id: uid
      })
    })
    .catch((err) => {
      console.log(err);
      throw new functions.https.HttpsError(
        "internal",
        " Unable to create Stripe user : " + err
      );
    });
})

Kotlin 函数

registerViewStubSignUpButton.setOnClickListener {
            FirebaseAuth.getInstance().createUserWithEmailAndPassword(registerViewStubEmailTextView.text.toString(), registerViewStubPasswordTextView.text.toString())
                .addOnCompleteListener {
                    if (!it.isSuccessful) return@addOnCompleteListener

                    // else if successful
                    uploadImageToFirebaseStorage()
                    uploadStripeCustomer()

                }
                .addOnFailureListener {
                    Toast.makeText(this, "Failed to create user: ${it.message}", Toast.LENGTH_SHORT).show()
                }
        }

private fun uploadImageToFirebaseStorage() {

        if (selectedPhotoUri == null) return

        val filename = UUID.randomUUID().toString()
        val ref = FirebaseStorage.getInstance().getReference("/customer_profile_images/$filename")

        ref.putFile(selectedPhotoUri!!)
            .addOnSuccessListener {
                ref.downloadUrl.addOnSuccessListener {
                    saveCustomerToFirebaseDatabase(it.toString())
                }
            }

    }

    private fun saveCustomerToFirebaseDatabase(profileImageUrl: String) {

        val registerStub = findViewById<ViewStub>(R.id.registerStub)
        val registerViewStubFullnameTextView = findViewById<TextInputEditText>(R.id.fullnameInputTextView)
        val registerViewStubUsernameTextView = findViewById<TextInputEditText>(R.id.usernameTextInputView)
        val registerViewStubEmailTextView = findViewById<TextInputEditText>(R.id.emailInputTextView)

        val uid = FirebaseAuth.getInstance().uid ?: ""
        val ref = FirebaseDatabase.getInstance().getReference("/customers/$uid")

        val customer = Customer(uid, registerViewStubFullnameTextView.text.toString(), registerViewStubUsernameTextView.text.toString(),
                                registerViewStubEmailTextView.text.toString(), profileImageUrl)

        ref.setValue(customer)
            .addOnSuccessListener {
                registerStub.alpha = 0f
                finish()
            }

    }

    private fun uploadStripeCustomer() {



    }

【问题讨论】:

  • 没有理由不能在 Android 和 iOS 应用程序之间共享相同的 HTTP 函数,假设其中没有任何特定的内容。
  • 谢谢!这么想,但需要检查。

标签: android firebase kotlin google-cloud-functions stripe-payments


【解决方案1】:

这取决于用例。如果 Firebase Cloud Function 对 iOS 和 Android 应用程序执行相同的任务,那么只使用一个应该可以工作。如果 iOS 和 Android 应用程序有一些不同的用例,那么应该使用两种不同的 Cloud Functions。

在您的情况下,当客户在 iOS 和 Android 应用程序中注册新帐户时,您似乎正在创建 stripeID,因此明智的做法是为 iOS 和 Android 应用程序使用一个 Firebase Cloud Functions Android 应用程序。

【讨论】:

  • 谢谢!是这样想的,我只是想检查一下。
猜你喜欢
  • 2018-12-07
  • 2014-03-30
  • 2019-03-28
  • 2023-01-18
  • 2014-11-12
  • 2016-11-20
  • 2021-11-09
  • 2018-06-04
  • 2015-07-03
相关资源
最近更新 更多