{"_id":"5aaf9d3c647c8c00296f1d5c","project":"54c83b5aab706219009e067b","initVersion":{"_id":"54dec8b6c2b4b70d009c3f0f","version":"1"},"user":{"_id":"59fa358b5bced80032a388aa","username":"","name":"Abhinav Arora"},"__v":0,"hidden":false,"createdAt":"2018-03-19T11:21:32.732Z","fullscreen":false,"htmlmode":false,"html":"","body":"We follow semantic versioning of our sdks\n[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Major Release\",\n  \"body\": \"This is a major release and it is highly recommended that you upgrade to it. We have added proper support for Flash Checkout as well as a bunch of other feature enhancements. We have also streamlined the integration process further. The older methods have been marked as deprecated and will be removed in the next major version release.\"\n}\n[/block]\nChangelog:\n\n- Distribution is via Maven Central Repository\n- Added support for device authentication as part of [Flash Checkout](https://razorpay.com/flashcheckout/)\n- Added optimisations for Netbanking pages\n- Improved Auto OTP reading UI\n- Improved integration through interfaces\n- Improved UI on tablets\n- Fixed PayUmoney topup flow. PayUmoney requires localstorage to work.\n- Fixed flow for netbanking in Canara bank. Their HTML/CSS required special handling to make it mobile accessible\n- Lot of under the hood refinements to make things faster and more robust\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Getting the SDK\"\n}\n[/block]\nWe are now distributing our SDK via Maven Central Repository. All further updates will be available through this channel.\n\nTo add Razorpay's Checkout SDK to your app, add the following dependency in your `build.gradle`:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"repositories {\\n    mavenCentral()\\n}\\n\\ndependencies {\\n    compile 'com.razorpay:checkout:1.4.7'\\n}\",\n      \"language\": \"java\",\n      \"name\": \"build.gradle\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Adding your API key\"\n}\n[/block]\nYou need to add your Razorpay API key to `AndroidManifest.xml`. You also need to add the `RECEIVE_SMS` permission.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<!-- Sample AndroidManifest.xml-->\\n<?xml version=\\\"1.0\\\" encoding=\\\"utf-8\\\"?>\\n<manifest xmlns:android=\\\"http://schemas.android.com/apk/res/android\\\">\\n  \\n  /**\\n   * Add the SMS permission\\n   *  if you want to enable Auto OTP Reading\\n   */\\n \\t<uses-permission android:name=\\\"android.permission.RECEIVE_SMS\\\" />\\n  \\n  <application\\n      android:allowBackup=\\\"true\\\"\\n      android:icon=\\\"@mipmap/ic_launcher\\\"\\n      android:label=\\\"@string/app_name\\\"\\n      android:theme=\\\"@style/AppTheme\\\"\\n      >\\n      <activity android:name=\\\".MainActivity\\\" android:label=\\\"@string/app_name\\\" >\\n        <intent-filter>\\n          <action android:name=\\\"android.intent.action.MAIN\\\" />\\n          <category android:name=\\\"android.intent.category.LAUNCHER\\\" />\\n        </intent-filter>\\n      </activity>\\n    \\n      /**\\n       * Add your API key \\n       */\\n      <meta-data\\n          android:name=\\\"com.razorpay.ApiKey\\\"\\n          android:value=\\\"YOUR_API_KEY\\\"\\n          />\\n  </application>\\n\\n</manifest>\",\n      \"language\": \"xml\",\n      \"name\": \"AndroidManifest.xml\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"android.permission.RECEIVE_SMS is not compulsory\",\n  \"body\": \"We use the `RECEIVE_SMS` permission to autofill the bank OTP received via SMS. If you do not want to ask your customers for this permission (for android M+ devices), you can safely ignore this in your manifest file and SDK will automatically disable this feature.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Using the SDK\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Backward Compatibility\",\n  \"body\": \"All the changes mentioned below are backward compatible. If you want to continue using the older structure, you just need to include the latest SDK through the process mentioned above. The SDK will work just like before.\\n\\nHowever, it is highly recommended that you refactor your code to support the latest structure. The older methods have been marked as deprecated and will be removed in the next major release.\"\n}\n[/block]\n## Basic Usage\n\n**Step 1 - Implement a `PaymentResultListener` in your `Activity`**\n\nYour activity will need to implement `PaymentResultListener` to receive callbacks for the\npayment result.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class MerchantActivity extends Activity implements PaymentResultListener {\\n  // ...\\n  \\n\\t@Override\\n  public void onPaymentSuccess(String razorpayPaymentID) {\\n\\t\\t/**\\n     * Add your logic here for a successfull payment response\\n     */\\n  }\\n\\n  @Override\\n  public void onPaymentError(int code, String response) {\\n\\t\\t/**\\n     * Add your logic here for a failed payment response\\n     */\\n  }\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Your Activity can get recreated\",\n  \"body\": \"Razorpay's payment process takes place in a new activity. Once the payment is complete, the SDK hands over control to a layer which calls these callback methods. Since there are two activities involved, your activity can get garbage collected / destroyed in case device is low on memory. Hence, these two methods should not depend on any variable that is not set through your lifecycle hooks.\\n\\nA good way to test if everything is fine is by enabling \\\"Don't Keep Activities\\\" in Developer Options under Settings.\"\n}\n[/block]\n**Step 2 - Preload `Checkout` (optional)** \n\nFor a smoother experience and swift loading of the `Checkout` form, you need to call the `preload` method of `Checkout` as early as possible in your payment flow. This can be done 2-3 screens before the end of your payment flow. It was observed that on poor 2G network it can take about 30-40 secs to preload resources.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public class SomeEarlierMerchantActivity extends Activity {\\n  \\n  // ...\\n  \\n\\t@Override\\n  public void onCreate(Bundle savedInstanceState) {\\n    super.onCreate(savedInstanceState);\\n    \\n    /**\\n     * Preload payment resources\\n     */\\n    Checkout.preload(getApplicationContext());\\n    \\n    // ...\\n  }\\n  \\n  // ...\\n  \\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n**Step 3 - Initiate a payment using `Checkout`**\n\nTo initiate a payment you need to create an instance of `Checkout` and pass the payment details and options as a `JSONObject`.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public void startPayment() {\\n\\t/**\\n   * Instantiate Checkout\\n   */\\n\\tCheckout checkout = new Checkout();\\n\\n  /**\\n   * Set your logo here\\n   */\\n\\tcheckout.setImage(R.drawable.logo);\\n  \\n  /**\\n   * Reference to current activity\\n   */\\n  final Activity activity = this;\\n  \\n  /**\\n   * Pass your payment options to the Razorpay Checkout as a JSONObject\\n   */\\n\\ttry {\\n\\t\\tJSONObject options = new JSONObject();\\n    \\n    /**\\n     * Merchant Name\\n     * eg: Rentomojo || HasGeek etc.\\n     */\\n\\t\\toptions.put(\\\"name\\\", \\\"Merchant Name\\\");\\n    \\n    /**\\n     * Description can be anything\\n     * eg: Order #123123\\n     *     Invoice Payment\\n     *     etc.\\n     */\\n\\t\\toptions.put(\\\"description\\\", \\\"Order #123456\\\");\\n    \\n\\t\\toptions.put(\\\"currency\\\", \\\"INR\\\");\\n    \\n    /**\\n     * Amount is always passed in PAISE\\n     * Eg: \\\"500\\\" = Rs 5.00\\n     */\\n    options.put(\\\"amount\\\", \\\"500\\\");\\n    \\n\\t\\tcheckout.open(activity, options);\\n\\t} catch(Exception e) {\\n\\t\\tLog.e(TAG, \\\"Error in starting Razorpay Checkout\\\", e);\\n\\t}\\n}\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n`Checkout.open()` launches the Checkout form where the user completes the payment and returns the payment result via appropriate callbacks on the `PaymentResultListener`.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Payment options in JSONObject\",\n  \"body\": \"All options that are available in `checkout.js` are also available in android. For reference, the list of allowed options is available <a href=\\\"https://docs.razorpay.com/docs/checkout-form#checkout-fields\\\" target=\\\"_blank\\\">here</a>\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Implementation details when using Fragment\",\n  \"body\": \"If you are calling the payment start method from inside a fragment, ensure that the `fragment`'s parent `activity` implements the `PaymentResultListener` interface.\"\n}\n[/block]\n## Error codes\n\nThe error codes that are returned in the `onPaymentError` method are:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"ERROR_CODE\",\n    \"h-1\": \"Description\",\n    \"0-0\": \"`Checkout.NETWORK_ERROR`\",\n    \"1-0\": \"`Checkout.INVALID_OPTIONS`\",\n    \"2-0\": \"`Checkout.PAYMENT_CANCELED`\",\n    \"0-1\": \"There was a network error, like internet connection going down etc.\",\n    \"1-1\": \"In case of issue in options passed in `checkout.open`\",\n    \"2-1\": \"User cancelled the payment\"\n  },\n  \"cols\": 2,\n  \"rows\": 3\n}\n[/block]\n# Customisation options\n\n## Custom logo in Checkout form\nBy default, Checkout form will use the logo you specified on Dashboard. You can also set a custom logo in our Checkout form. For this you need to call the following method _before_ you call `open` method.\n\n```\nint image = R.drawable.logo; // Can be any drawable\ncheckout.setImage(image);\n```\n\nIf you pass both, image in `options` as well as through this method, the image from drawables is picked up.\n\n## **Disabling Fullscreen in Checkout Activity:**\n\nThe Checkout form runs in a separate activity. This activity picks up theme from Manifest. So if you have a fullscreen theme, even the Checkout will run in fullscreen. However, we have observed that conversion rates get lower in fullscreen mode since user also needs to switch apps for OTP etc.\n\nIf your app is in a fullscreen mode, you can disable it for Checkout by calling the following method:\n\n```\ncheckout.setFullScreenDisable(true)\n```\n## **Clear User Data from SDK:**\n\nThe SDK store some of the user data like email, contact number and user session specific cookies, it is useful when the same user does repeated payment in a single app. If the current user logs out from the app and new user login from the app, you might want to clear data of the older user from the SDK. \n\nYou can call this method anywhere in your app to clear user data from the SDK.\n\n```\nCheckout.clearUserData(Context)\n```\n\n# Proguard rules\n\nIf you're using proguard for your builds, you need to add the following lines to your proguard file\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"-keepclassmembers class * {\\n    @android.webkit.JavascriptInterface <methods>;\\n}\\n\\n-keepattributes JavascriptInterface\\n-keepattributes *Annotation*\\n\\n-dontwarn com.razorpay.**\\n-keep class com.razorpay.** {*;}\\n\\n-optimizations !method/inlining/*\\n\\n-keepclasseswithmembers class * {\\n  public void onPayment*(...);\\n}\",\n      \"language\": \"java\",\n      \"name\": \"Proguard Config\"\n    }\n  ]\n}\n[/block]","slug":"android","title":"Android"}

Android


We follow semantic versioning of our sdks [block:callout] { "type": "success", "title": "Major Release", "body": "This is a major release and it is highly recommended that you upgrade to it. We have added proper support for Flash Checkout as well as a bunch of other feature enhancements. We have also streamlined the integration process further. The older methods have been marked as deprecated and will be removed in the next major version release." } [/block] Changelog: - Distribution is via Maven Central Repository - Added support for device authentication as part of [Flash Checkout](https://razorpay.com/flashcheckout/) - Added optimisations for Netbanking pages - Improved Auto OTP reading UI - Improved integration through interfaces - Improved UI on tablets - Fixed PayUmoney topup flow. PayUmoney requires localstorage to work. - Fixed flow for netbanking in Canara bank. Their HTML/CSS required special handling to make it mobile accessible - Lot of under the hood refinements to make things faster and more robust [block:api-header] { "type": "basic", "title": "Getting the SDK" } [/block] We are now distributing our SDK via Maven Central Repository. All further updates will be available through this channel. To add Razorpay's Checkout SDK to your app, add the following dependency in your `build.gradle`: [block:code] { "codes": [ { "code": "repositories {\n mavenCentral()\n}\n\ndependencies {\n compile 'com.razorpay:checkout:1.4.7'\n}", "language": "java", "name": "build.gradle" } ] } [/block] [block:api-header] { "type": "basic", "title": "Adding your API key" } [/block] You need to add your Razorpay API key to `AndroidManifest.xml`. You also need to add the `RECEIVE_SMS` permission. [block:code] { "codes": [ { "code": "<!-- Sample AndroidManifest.xml-->\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\">\n \n /**\n * Add the SMS permission\n * if you want to enable Auto OTP Reading\n */\n \t<uses-permission android:name=\"android.permission.RECEIVE_SMS\" />\n \n <application\n android:allowBackup=\"true\"\n android:icon=\"@mipmap/ic_launcher\"\n android:label=\"@string/app_name\"\n android:theme=\"@style/AppTheme\"\n >\n <activity android:name=\".MainActivity\" android:label=\"@string/app_name\" >\n <intent-filter>\n <action android:name=\"android.intent.action.MAIN\" />\n <category android:name=\"android.intent.category.LAUNCHER\" />\n </intent-filter>\n </activity>\n \n /**\n * Add your API key \n */\n <meta-data\n android:name=\"com.razorpay.ApiKey\"\n android:value=\"YOUR_API_KEY\"\n />\n </application>\n\n</manifest>", "language": "xml", "name": "AndroidManifest.xml" } ] } [/block] [block:callout] { "type": "warning", "title": "android.permission.RECEIVE_SMS is not compulsory", "body": "We use the `RECEIVE_SMS` permission to autofill the bank OTP received via SMS. If you do not want to ask your customers for this permission (for android M+ devices), you can safely ignore this in your manifest file and SDK will automatically disable this feature." } [/block] [block:api-header] { "type": "basic", "title": "Using the SDK" } [/block] [block:callout] { "type": "info", "title": "Backward Compatibility", "body": "All the changes mentioned below are backward compatible. If you want to continue using the older structure, you just need to include the latest SDK through the process mentioned above. The SDK will work just like before.\n\nHowever, it is highly recommended that you refactor your code to support the latest structure. The older methods have been marked as deprecated and will be removed in the next major release." } [/block] ## Basic Usage **Step 1 - Implement a `PaymentResultListener` in your `Activity`** Your activity will need to implement `PaymentResultListener` to receive callbacks for the payment result. [block:code] { "codes": [ { "code": "public class MerchantActivity extends Activity implements PaymentResultListener {\n // ...\n \n\t@Override\n public void onPaymentSuccess(String razorpayPaymentID) {\n\t\t/**\n * Add your logic here for a successfull payment response\n */\n }\n\n @Override\n public void onPaymentError(int code, String response) {\n\t\t/**\n * Add your logic here for a failed payment response\n */\n }\n}", "language": "java" } ] } [/block] [block:callout] { "type": "warning", "title": "Your Activity can get recreated", "body": "Razorpay's payment process takes place in a new activity. Once the payment is complete, the SDK hands over control to a layer which calls these callback methods. Since there are two activities involved, your activity can get garbage collected / destroyed in case device is low on memory. Hence, these two methods should not depend on any variable that is not set through your lifecycle hooks.\n\nA good way to test if everything is fine is by enabling \"Don't Keep Activities\" in Developer Options under Settings." } [/block] **Step 2 - Preload `Checkout` (optional)** For a smoother experience and swift loading of the `Checkout` form, you need to call the `preload` method of `Checkout` as early as possible in your payment flow. This can be done 2-3 screens before the end of your payment flow. It was observed that on poor 2G network it can take about 30-40 secs to preload resources. [block:code] { "codes": [ { "code": "public class SomeEarlierMerchantActivity extends Activity {\n \n // ...\n \n\t@Override\n public void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n \n /**\n * Preload payment resources\n */\n Checkout.preload(getApplicationContext());\n \n // ...\n }\n \n // ...\n \n}", "language": "java" } ] } [/block] **Step 3 - Initiate a payment using `Checkout`** To initiate a payment you need to create an instance of `Checkout` and pass the payment details and options as a `JSONObject`. [block:code] { "codes": [ { "code": "public void startPayment() {\n\t/**\n * Instantiate Checkout\n */\n\tCheckout checkout = new Checkout();\n\n /**\n * Set your logo here\n */\n\tcheckout.setImage(R.drawable.logo);\n \n /**\n * Reference to current activity\n */\n final Activity activity = this;\n \n /**\n * Pass your payment options to the Razorpay Checkout as a JSONObject\n */\n\ttry {\n\t\tJSONObject options = new JSONObject();\n \n /**\n * Merchant Name\n * eg: Rentomojo || HasGeek etc.\n */\n\t\toptions.put(\"name\", \"Merchant Name\");\n \n /**\n * Description can be anything\n * eg: Order #123123\n * Invoice Payment\n * etc.\n */\n\t\toptions.put(\"description\", \"Order #123456\");\n \n\t\toptions.put(\"currency\", \"INR\");\n \n /**\n * Amount is always passed in PAISE\n * Eg: \"500\" = Rs 5.00\n */\n options.put(\"amount\", \"500\");\n \n\t\tcheckout.open(activity, options);\n\t} catch(Exception e) {\n\t\tLog.e(TAG, \"Error in starting Razorpay Checkout\", e);\n\t}\n}", "language": "java" } ] } [/block] `Checkout.open()` launches the Checkout form where the user completes the payment and returns the payment result via appropriate callbacks on the `PaymentResultListener`. [block:callout] { "type": "info", "title": "Payment options in JSONObject", "body": "All options that are available in `checkout.js` are also available in android. For reference, the list of allowed options is available <a href=\"https://docs.razorpay.com/docs/checkout-form#checkout-fields\" target=\"_blank\">here</a>" } [/block] [block:callout] { "type": "info", "title": "Implementation details when using Fragment", "body": "If you are calling the payment start method from inside a fragment, ensure that the `fragment`'s parent `activity` implements the `PaymentResultListener` interface." } [/block] ## Error codes The error codes that are returned in the `onPaymentError` method are: [block:parameters] { "data": { "h-0": "ERROR_CODE", "h-1": "Description", "0-0": "`Checkout.NETWORK_ERROR`", "1-0": "`Checkout.INVALID_OPTIONS`", "2-0": "`Checkout.PAYMENT_CANCELED`", "0-1": "There was a network error, like internet connection going down etc.", "1-1": "In case of issue in options passed in `checkout.open`", "2-1": "User cancelled the payment" }, "cols": 2, "rows": 3 } [/block] # Customisation options ## Custom logo in Checkout form By default, Checkout form will use the logo you specified on Dashboard. You can also set a custom logo in our Checkout form. For this you need to call the following method _before_ you call `open` method. ``` int image = R.drawable.logo; // Can be any drawable checkout.setImage(image); ``` If you pass both, image in `options` as well as through this method, the image from drawables is picked up. ## **Disabling Fullscreen in Checkout Activity:** The Checkout form runs in a separate activity. This activity picks up theme from Manifest. So if you have a fullscreen theme, even the Checkout will run in fullscreen. However, we have observed that conversion rates get lower in fullscreen mode since user also needs to switch apps for OTP etc. If your app is in a fullscreen mode, you can disable it for Checkout by calling the following method: ``` checkout.setFullScreenDisable(true) ``` ## **Clear User Data from SDK:** The SDK store some of the user data like email, contact number and user session specific cookies, it is useful when the same user does repeated payment in a single app. If the current user logs out from the app and new user login from the app, you might want to clear data of the older user from the SDK. You can call this method anywhere in your app to clear user data from the SDK. ``` Checkout.clearUserData(Context) ``` # Proguard rules If you're using proguard for your builds, you need to add the following lines to your proguard file [block:code] { "codes": [ { "code": "-keepclassmembers class * {\n @android.webkit.JavascriptInterface <methods>;\n}\n\n-keepattributes JavascriptInterface\n-keepattributes *Annotation*\n\n-dontwarn com.razorpay.**\n-keep class com.razorpay.** {*;}\n\n-optimizations !method/inlining/*\n\n-keepclasseswithmembers class * {\n public void onPayment*(...);\n}", "language": "java", "name": "Proguard Config" } ] } [/block]