如何集成 phonePe 支付网关

问题描述 投票:0回答:1

我正在尝试 Integration.Phonepe 安卓应用支付网关

public class PhonePePayActivity extends BaseActivity {


String TAG ="PhonePePayActivity";
private static int B2B_PG_REQUEST_CODE = 777;

@Override
protected int getLayoutId() {
    return R.layout.activity_phone_pe_pay;
}

@Override
public void setView() {
    super.setView();

}

String apiEndPoint = "/pg/v1/pay";
String SaltKey = "a6334ff7-da0e-4d51-a9ce-76b97d518b1e";
int KeyIndex  = 1;

@RequiresApi(api = Build.VERSION_CODES.O)
@OnClick({R.id.pay_button})
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.pay_button:

            HashMap<String, Object> data = new HashMap();
            data.put("merchantTransactionId",createTrnId());    //String. Mandatory
            data.put("merchantId", "ON24MARTUAT");             //String. Mandatory
            data.put("merchantUserId", "u123");             //String. Conditional
            data.put("amount",100);                         //Long. Mandatory
            data.put("mobileNumber","8510988965");          //String. Optional
            data.put("callbackUrl","https://webhook.site/callback-url");

            PaymentInstrumentPe mPaymentInstrument = new PaymentInstrumentPe();
            mPaymentInstrument.setType("UPI_INTENT");          
            mPaymentInstrument.setTargetApp("com.phonepe.app");  
            data.put("paymentInstrument",mPaymentInstrument);  

            DeviceContextPe mDeviceContextPe = new DeviceContextPe();
            mDeviceContextPe.setDeviceOS("ANDROID");          // ENUM. Mandatory
            data.put("deviceContext", mDeviceContextPe);   //OBJECT. Mandatory

            String originalInput = new Gson().toJson(data);
            String base64Body = Base64.getEncoder().encodeToString(originalInput.getBytes());

            Log.e(TAG, "onClick: " + base64Body );

            String checksum = sha256(base64Body + apiEndPoint + SaltKey) + "###"+ KeyIndex;

            Log.e(TAG, "onClick: "+ checksum );

            B2BPGRequest b2BPGRequest = new B2BPGRequestBuilder()
                    .setData(base64Body)
                    .setChecksum(checksum)
                    .setUrl(apiEndPoint)
                    .build();
            try {
                startActivityForResult(PhonePe.getImplicitIntent(
                        this, b2BPGRequest, "com.phonepe.app.preprod"),B2B_PG_REQUEST_CODE);
            } catch(PhonePeInitException e){
                Log.e(TAG, "onClick: error-" + e.toString() );
                e.printStackTrace();
            }
            break;


    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == B2B_PG_REQUEST_CODE) {

       // Log.e(TAG, "onActivityResult: " +data.toString() );
  /*This callback indicates only about completion of UI flow.
        Inform your server to make the transaction
        status call to get the status. Update your app with the
        success/failure status.*/

    }
}

private String createTrnId() {
    Date date = new Date();
    long createTransactionId = date.getTime();

    return "on24m_"+ createTransactionId;
}



private static String sha256(String input) {
    try {
        MessageDigest digest = MessageDigest.getInstance("SHA-256");
        byte[] hash = digest.digest(input.getBytes("UTF-8"));
        StringBuilder hexString = new StringBuilder();

        for (byte b : hash) {
            String hex = Integer.toHexString(0xff & b);
            if (hex.length() == 1) hexString.append('0');
            hexString.append(hex);
        }

        return hexString.toString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
  }
}

我没有得到回应和其中的所有细节(得到回应

出了点问题:404

).谢谢,如果你能帮我解决这个问题。

我正在关注这个文档。

PG SDK 详情 Android PG SDK -

https://developer.phonepe.com/v1/docs/android-pg-sdk-integration

PAY API 详情PAY API -

https://developer.phonepe.com/v1/reference/pay-api

响应授权检查状态 API -

https://developer.phonepe.com/v1/reference/check-status-api

服务器到服务器响应 -

https://developer.phonepe.com/v1/reference/server-to-server-callback-4

android payment-gateway
1个回答
0
投票

我收到错误代码 400。您知道答案了吗?

© www.soinside.com 2019 - 2024. All rights reserved.