【发布时间】: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