The Unified Payments Interface (UPI) and BHIM (Bharat Interface for Money) are significant interventions by the government to promote digital payments in our country.This is sample code helpful for developers.
public class UPIExample extends AppCompatActivity { String payeeAddress = "9100239922@upi"; String payeeName = "Raj kumar"; String transactionNote = "Ex-Test Case"; String amount = "10"; String cur_unit = "INR"; @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.submit).setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { Uri uri = Uri.parse("upi://pay?pa=" + payeeAddress + "&pn=" + payeeName + "&tn=" + transactionNote + "&am=" + amount + "&cu=" + cur_unit); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivityForResult(intent, 1); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (data != null) { String response_ok = data.getStringExtra("response"); String search = "SUCCESS"; if (response_ok.toLowerCase().contains(search.toLowerCase())) { Toast.makeText(this, "Payment Successful", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "Payment Failed", Toast.LENGTH_LONG).show(); } } } }
Comments
Post a Comment