//Add the dependency in android razorpay sdk implementation 'com.razorpay:checkout:1.6.6'
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.thecodehubs.razorpay"> <uses-permission android:name="android.permission.INTERNET" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity">l̥ <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- Add your API key here --> <meta-data android:name="com.razorpay.ApiKey" android:value="Add your API key here"/> </application> </manifest>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#007C9E" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="100dp" android:layout_marginLeft="20dp" android:layout_marginRight="20dp" android:orientation="vertical" android:gravity="center" > <RelativeLayout android:layout_width="match_parent" android:layout_height="110dp" > <LinearLayout android:layout_width="match_parent" android:layout_height="80dp" android:layout_alignParentBottom="true" android:background="#E2E2E2" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="35dp" android:paddingBottom="0dp" android:textSize="12sp" android:text="Order #RZP42" /> </LinearLayout> <ImageView android:layout_width="60dp" android:layout_height="60dp" android:layout_centerHorizontal="true" android:background="#FFFFFF" android:src="@drawable/rzp" /> </RelativeLayout> <LinearLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:orientation="vertical" android:paddingTop="15dp" android:background="#f2f2f2" android:gravity="center" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingTop="0dp" android:paddingBottom="5dp" android:textSize="20sp" android:text="Razorpay T-Shirt" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingTop="0dp" android:paddingBottom="0dp" android:textSize="12sp" android:text="INR 1.00" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingTop="10dp" android:paddingBottom="0dp" android:textSize="12sp" android:textStyle="italic" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:textColor="@android:color/holo_red_dark" android:gravity="center_horizontal" android:text="Transaction is for testing purpose and your deducted amount will get refunded in 3-5 business days " /> <TextView android:id="@+id/txt_privacy_policy" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:paddingTop="10dp" android:paddingBottom="0dp" android:textSize="12sp" android:textStyle="italic" android:layout_marginStart="16dp" android:layout_marginEnd="16dp" android:textColor="@android:color/holo_red_dark" android:gravity="center_horizontal" android:text="Privacy Policy" /> <Button android:id="@+id/btn_pay" android:layout_width="wrap_content" android:layout_height="36dp" android:layout_marginTop="20dp" android:layout_marginBottom="20dp" android:layout_gravity="center_horizontal" android:paddingRight="20dp" android:paddingLeft="20dp" android:background="@drawable/green_button" android:textSize="14sp" android:textColor="#fcfcfc" android:text="Purchase" /> </LinearLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingLeft="20dp" android:paddingRight="20dp" android:background="@drawable/secured_by_bg" android:textSize="12sp" android:textColor="#a1ddee" android:textStyle="italic" android:text="Secure Payments by Razorpay" /> </LinearLayout> </RelativeLayout>
Now on PaymentActivity.java implement payment result listener and override the methods. To start the razor pay payment, you need to create a JSON object which contains all the information about the payer and receiver like name, description, amount, email, contact, etc.
package com.thecodehubs.razorpay.java; import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import com.razorpay.Checkout; import com.razorpay.PaymentResultListener; import com.razorpay.sampleapp.R; import org.json.JSONObject; public class PaymentActivity extends Activity implements PaymentResultListener { private static final String TAG = PaymentActivity.class.getSimpleName(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_payment); /* To ensure faster loading of the Checkout form, call this method as early as possible in your checkout flow. */ Checkout.preload(getApplicationContext()); // Payment button created by you in XML layout Button button = (Button) findViewById(R.id.btn_pay); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startPayment(); } }); TextView privacyPolicy = (TextView) findViewById(R.id.txt_privacy_policy); privacyPolicy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent httpIntent = new Intent(Intent.ACTION_VIEW); httpIntent.setData(Uri.parse("https://razorpay.com/sample-application/")); startActivity(httpIntent); } }); } public void startPayment() { final Activity activity = this; final Checkout co = new Checkout(); try { JSONObject options = new JSONObject(); options.put("name", "Razorpay Corp"); options.put("description", "Demoing Charges"); options.put("send_sms_hash",true); options.put("allow_rotation", true); //You can omit the image option to fetch the image from dashboard options.put("image", "https://s3.amazonaws.com/rzp-mobile/images/rzp.png"); options.put("currency", "INR"); options.put("amount", "100"); JSONObject preFill = new JSONObject(); preFill.put("email", "Your Registration Email Id"); preFill.put("contact", "Your Registration Contact Number"); options.put("prefill", preFill); co.open(activity, options); } catch (Exception e) { Toast.makeText(activity, "Error in payment: " + e.getMessage(), Toast.LENGTH_SHORT) .show(); e.printStackTrace(); } } @Override public void onPaymentSuccess(String razorpayPaymentID) { try { Toast.makeText(this, "Payment Successful: " + razorpayPaymentID, Toast.LENGTH_SHORT).show(); } catch (Exception e) { Log.e(TAG, "Exception in onPaymentSuccess", e); } } @Override public void onPaymentError(int code, String response) { try { Toast.makeText(this, "Payment failed: " + code + " " + response, Toast.LENGTH_SHORT).show(); } catch (Exception e) { Log.e(TAG, "Exception in onPaymentError", e); } } }
Congratulations!!! you have developed your Razorpay Payment Gateway Integration. in Android Studio and now just keep following the rest of the tutorial step by step to become a great Android Developer. All the very best.
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular