如何使用Firebase云功能在Paypal android中确认付款发件人ID

时间:2018-06-24 17:54:02

标签: android firebase paypal

我正在使用Firebase云功能作为服务器端使用PayPal付款制作一个Android应用程序。用户汇款,汇款后返回一个动作。

我如何确认汇款人的ID,以允许向该特定用户退回操作,例如向用户钱包中添加的订阅或硬币?

 if ( requestCode == PAYPAL_REQUEST_CODE ) {
      if ( resultCode == Activity.RESULT_OK ) {
      PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
      if ( confirm != null ) {
           try {
               payoutRequest();

           {
                JSONObject jsonObj = new JSONObject(confirm.toJSONObject().toString());
                String paymentResponse = jsonObj.getJSONObject("response").getString("state");

                if ( paymentResponse.equals("approved") ) {

                }
           }
           } catch (JSONException e) {
           e.printStackTrace();
           }
      }
      } else if ( resultCode == Activity.RESULT_CANCELED ) {
      Toast.makeText(getContext(), "payment unsuccessful", 
       Toast.LENGTH_LONG).show();

      } else if ( resultCode == PaymentActivity.RESULT_EXTRAS_INVALID ) {
      }
 }
 }

 public void payoutRequest() {
 OkHttpClient okHttpClient = new OkHttpClient();
 JSONObject postData = new JSONObject();
 try {
      postData.put("uid", uid);

 } catch (JSONException e) {
      e.printStackTrace();
 }
 RequestBody body = RequestBody.create(MEDIA_TYPE, postData.toString());
 final Request request = new Request.Builder()
     .url("https://us-central1-chitchat-5a9bd.cloudfunctions.net/payout")
     .post(body)
     .addHeader("Content-Type", "application/json")
     .addHeader("cache-control", "no-cache")
     .addHeader("Authorization", "Your Token")
     .build();

 okHttpClient.newCall(request).enqueue(new Callback() {
      @Override
      public void onFailure(@NonNull Call call, @NonNull IOException e) {
      }

      @Override
      public void onResponse(@NonNull Call call, @NonNull Response response) 
       throws IOException {
      int responsecode = response.code();

      }
 });
 }

firebase函数的一部分

'use-strict'
  const functions = require('firebase-functions');
  const paypal=require('paypal-rest-sdk');
    const admin=require('firebase-admin');
     admin.initializeApp(functions.config().firebase);

paypal.configure({
mode:'sandbox',
client_id:  functions.config().paypal.client_id,
client_secret: functions.config().paypal.client_secret
});

const sender_batch_id = Math.random().toString(36).substring(9);

const payReq=JSON.stringify({
        sender_batch_header: {
            sender_batch_id: sender_batch_id,
            email_subject: "You have a nice  payment"
        },
        items: [
            {
                recipient_type: "EMAIL",
                amount: {
                    value: 0.90,
                    currency: "USD"
                },
                receiver: "amrmahmoudM@app.com",
                note: "Thank you very much.",
                sender_item_id: "item_3"
            }
        ]
});
paypal.payout.create(payReq,(error, payout)=>{
    if (error) {
        console.warn(error.res);
        res.status('500').end();
        throw error;

    }else{
        console.info("payout created");
        console.info(payout);
        res.status('200').end();

    }
});
});

0 个答案:

没有答案