Instamojo交易ID不是Android应用上的唯一响应

时间:2017-08-08 09:38:18

标签: php android codeigniter-3 instamojo

当我尝试在我的设备上集成instamojo支付SDK时,我在Android应用程序上收到错误。我创建并遵循了instamojo docs中提到的所有步骤。

这是我的代码:在我的后端: 此代码使用CI(CodeIgniter)框架以PHP编写。

public function test_post()
    {
        $test_array = [
            'client_id' => '1Ry0WvkKoYEFFkhhh5JjdyRiHBkH3oaEUu8iddsXqQHNcxH',
            'client_secret' => 'H0teU3R2rspXrPaaQZK4cE8cVCMrEhssHF2xQDI76n1Gg2tbJ9Bw7eHOZDG4BasgTlmfWViTMQtGPoXxYORaPOas2eXLGSZXbJLhn0Dpegej6uY5uKjcvMGjewsE1NPaFATmkvbu',
            'grant_type'   => 'client_credentials'
        ];


        $ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://test.instamojo.com/oauth2/token/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $test_array);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

// in real life you should use something like:
// curl_setopt($ch, CURLOPT_POSTFIELDS, 
//          http_build_query(array('postvar1' => 'value1')));

// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);


$server_output = curl_exec ($ch);

if(curl_error($ch))
{
    echo 'error:' . curl_error($ch);
}

curl_close ($ch);




$jsonOutput=json_decode($server_output);
$response['access_token']=$jsonOutput->access_token;


$response['transaction_id']=$this->getGUIDnoHash();
$this->response($response);


 }

这是唯一的哈希函数代码:

public function getGUIDnoHash(){
            mt_srand((double)microtime()*10000);
            $charid = md5(uniqid(rand(), true));
            $c = unpack("C*",$charid);
            $c = implode("",$c);

            return substr($c,0,20);
    }

我的Android代码:

 private void fetchTokenAndTransactionID() {


        JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(com.android.volley.Request.Method.POST, "http://www.hoodler.in/api2/Instamojo/test", null, new com.android.volley.Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                String responseString;
                String errorMessage = "";

                try {


                    if (response.has("error")) {
                        errorMessage = response.getString("error");
                    } else {
                        accessToken = response.getString("access_token");

                        transactionID = createTransactionID();
                        Log.e("Transaction Id", transactionID);

                        createOrder(accessToken, transactionID);
                    }
                }catch (Exception e)
                {
                    Log.e("Error",""+e);

                }
            }
        }, new com.android.volley.Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Log.e("Error"," d"+error.getMessage());
            }
        });
        requestQueue.add(jsonObjectRequest);

获取访问令牌和事务ID后创建了一个订单,这里是代码。我在这一部分收到错误。

 private void createOrder(String accessToken, String transactionID) {
        String name = nameBox.getText().toString();
        final String email = emailBox.getText().toString();
        String phone = phoneBox.getText().toString();
        String amount = amountBox.getText().toString();
        String description = descriptionBox.getText().toString();

        //Create the Order
        Order order = new Order(accessToken, transactionID, name, email, phone, amount, description);

        //set webhook
        order.setWebhook("http://www.hoodler.in/api/Mobile/");

        //Validate the Order
        if (!order.isValid()) {
            //oops order validation failed. Pinpoint the issue(s).

            if (!order.isValidName()) {
                nameBox.setError("Buyer name is invalid");
            }

            if (!order.isValidEmail()) {
                emailBox.setError("Buyer email is invalid");
            }

            if (!order.isValidPhone()) {
                phoneBox.setError("Buyer phone is invalid");
            }

            if (!order.isValidAmount()) {
                amountBox.setError("Amount is invalid or has more than two decimal places");
            }

            if (!order.isValidDescription()) {
                descriptionBox.setError("Description is invalid");
            }

            if (!order.isValidTransactionID()) {
                showToast("Transaction is Invalid");
            }

            if (!order.isValidRedirectURL()) {
                showToast("Redirection URL is invalid");
            }

            if (!order.isValidWebhook()) {
                showToast("Webhook URL is invalid");
            }

            return;
        }

        //Validation is successful. Proceed
        dialog.show();
        Request request = new Request(order, new OrderRequestCallBack() {
            @Override
            public void onFinish(final Order order, final Exception error) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        dialog.dismiss();
                        if (error != null) {
                            if (error instanceof Errors.ConnectionError) {
                                showToast("No internet connection");
                            } else if (error instanceof Errors.ServerError) {
                                showToast("Server Error. Try again");
                            } else if (error instanceof Errors.AuthenticationError) {
                                showToast("Access token is invalid or expired. Please Update the token!!");
                            } else if (error instanceof Errors.ValidationError) {
                                // Cast object to validation to pinpoint the issue
                                Errors.ValidationError validationError = (Errors.ValidationError) error;



                                if (!validationError.isValidRedirectURL()) {
                                    showToast("Redirect url is invalid");
                                    return;
                                }

                                if (!validationError.isValidWebhook()) {
                                    showToast("Webhook url is invalid");
                                    return;
                                }

                                if (!validationError.isValidPhone()) {
                                    phoneBox.setError("Buyer's Phone Number is invalid/empty");
                                    return;
                                }

                                if (!validationError.isValidEmail()) {
                                    emailBox.setError("Buyer's Email is invalid/empty");
                                    return;
                                }

                                if (!validationError.isValidAmount()) {
                                    amountBox.setError("Amount is either less than Rs.9 or has more than two decimal places");
                                    return;
                                }

                                if (!validationError.isValidName()) {
                                    nameBox.setError("Buyer's Name is required");
                                    return;
                                }
                            } else {
                                showToast(error.getMessage());
                            }
                            return;
                        }

                        startPreCreatedUI(order);
                    }
                });
            }
        });

        request.execute();
    }

每次说明交易ID并不是唯一的,尽管我正在处理唯一性。

0 个答案:

没有答案