API Key Activation

On every launch of your application use validate activation method to check if the API key is activated, else use the activate api method to activate the API.


Validate activation

Create an object of Account Validator class and call the isAccountActivated() method from the onCreate() method of your Application class.

πŸ‘

Callout!

The Is accountActivated() method will return true if the API keys are already activated. Else it will return false. If the method returns false , populate Activation Activity class of activation UI screen with fields of EditText to capture merchant API key and click the button to activate.

AccountValidator validator = new AccountValidator(getApplicationContext());
if (!validator.isAccountActivated()) {
  Intent i = new Intent(getApplicationContext(), ActivationActivity.class);
  startActivity(i);
}

Activate API

Method: accountActivation()

Create an Account Validator class object and call accountActivation() method by passing the parameters of handler object, merchant API key , partner API key as inputs. Response will be either success or fail with appropriate message

Request parameter

ParameterDescriptionExample
Merchant API Key
mandatory
String PayU uses this key for authentication and authorization over the secured layer.ABC515ABC515
Partner API
mandatory
String PayU uses this key for authentication and authorization over the secured layer. ABC515ABC515
Handler
mandatory
Handler
Handlers are used to passing the data and receiving the data between the SDK and application UI.
handler

Sample request

String mkey = merchantKey.getText().toString();
if (mkey != null) {
  if (mkey.length() == 12) {
    try {
      AccountValidatorvalidator = new
      AccountValidator(getApplicationContext());
      validator.accountActivation(handler, MerchantAPIKey,
        partnerAPIKey);
    } catch (RuntimeException e) {
      e.printStackTrace();
    }
  } else {
    Toast.makeText(ActivationActivity.this,
      "Enter the 12 characters key", Toast.LENGTH_SHORT).show();
  }
} else {
  Toast.makeText(ActivationActivity.this, "Enter the key",
    Toast.LENGTH_SHORT).show();
}
}

Response parameter

ParameterDescription
SuccessIf the API Key Activated
FailIf API Key is not activated (Ex:-Account block, Invalid API key).

Sample response

private Handler handler = new Handler() {
  public void handleMessage(android.os.Message msg) {
    if (msg.what == SUCCESS) {
      Intent i = new Intent(ActivationActivity.this,
        MainActivity.class);
      startActivity(i);
    } else if (
      msg.what == FAIL) {
      Toast.makeText(ActivationActivity.this, (String) msg.obj,
        Toast.LENGTH_SHORT).show();
    }
  };
};