2021年3月24日星期三

Firebase function return to data to android

What am Trying to do : Simply Return data from firebase cloud function.

The function is used to create a payment order in the payment gateway's server.

My required data about the order's details are present in the function(err,data)(Refer code) I need this data sent back to my android app.

Problem I faced : I could see the data printed in the firebase console's log but it doesn't return to my android app back.

My firebase cloud function :

const functions = require("firebase-functions");  exports.order = functions.https.onCall((amnt, response) => {        const Ippopay = require('node-ippopay');        var ippopay_instance = new Ippopay({          public_key: 'pk_live_0WZhCNC5l7PJ',          secret_key: 'sk_live_GXc8SLdxkBp',        });                ippopay_instance.createOrder({          amount: amnt,           currency: 'DOLLAR',          payment_modes: "cc,dc,nb,cheque",          customer: {              name: "Test",              email: "test@gmail.com",              phone: {                  country_code: "42",                  national_number: "4376543210"              }          }      }, function  (err, data){                  return data.order.order_id;      });   });   

My android client side code :

public class Payment extends AppCompatActivity implements IppoPayListener {        Button pay;      EditText amount;      private FirebaseFunctions mFunctions;        TextView order_data;      String data;        @Override      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_payment);      }      @Override      protected void onPostCreate(@Nullable Bundle savedInstanceState) {          super.onPostCreate(savedInstanceState);          pay=findViewById(R.id.pay_button);          amount=findViewById(R.id.user_amount);          order_data=findViewById(R.id.data_text);          pay.setOnClickListener(new View.OnClickListener() {              @Override              public void onClick(View v) {                  Log.d("PAY Button clicked", "yes");                  mFunctions = FirebaseFunctions.getInstance("us-central1");                                   mFunctions.getHttpsCallable("order").call(5).continueWith(new Continuation<HttpsCallableResult, Object>() {                      @Override                      public Object then(@NonNull Task<HttpsCallableResult> task) throws Exception {                          HttpsCallableResult result=task.getResult();                          if(result !=null)                          {                              data=result.getData().toString();                              return result.getData().toString();                            }                          return null;                      }                   });                  order_data.setText(data);                  onPaymentClick();                }          });      }  

I'm a Beginner so there's a high possibility of some dead silly mistakes. :)

https://stackoverflow.com/questions/66793912/firebase-function-return-to-data-to-android March 25, 2021 at 02:02PM

没有评论:

发表评论