Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.

Library to use ZarinPal payment service in android apps

Notifications You must be signed in to change notification settings

mderis/Zarinpal-Android-Sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zarinpal Android Sample

Library to use ZarinPal payment service in android apps

This library lets android developers have in-app-purchase using ZarinPal service.

##How to use ###Prepare project:

  1. Download and add this jar file into your project as a library:
  2. Copy jar file in project-directory/app/libs/
  3. Right click on file in Android Studio and click on Add as library
  4. Add our payment Activity to your project manifest file as shown below:
<application>
  .
  .
  .
     <activity android:name="ir.moslem_deris.apps.zarinpal.PaymentActivity"/>
  .
  .
  .
</application>
  1. Add Internet permission to your manifest file (for android 5 and below):
  <uses-permission android:name="android.permission.INTERNET"/>
  1. Add okHttp library to your project dependencies:

compile 'com.squareup.okhttp3:okhttp:3.5.0'

###How to code: Create a Payment object and put the data you want in it like the code below:

Payment payment = new PaymentBuilder()
                .setMerchantID("4ff2f25a-82c8-45eb-b540-4c5b5ee8aeb5")  //  This is an example, put your own merchantID here.
                .setAmount(100)                                         //  Amount in Toman
                .setDescription("put payment description here")
                .setEmail("moslem.deris@gmail.com")                     //  This field is not necessary.
                .setMobile("09123456789")                               //  This field is not necessary.
                .create();

Everywhere you want to run the pay method just call ZarinPal.pay(x, y, z);

x: Current activity, just passthis

y: your Payment object

z: OnPaymentListener

###Example code

ZarinPal.pay(this, payment, new OnPaymentListener() {
            @Override
            public void onSuccess(String refID) {
                Log.wtf("TAG", "HOOOORAAAY!!! your refID is: " + refID);
            }

            @Override
            public void onFailure(ZarinPalError error) {
                String errorMessage = "";
                switch (error){
                    case INVALID_PAYMENT: errorMessage = "پرداخت تایید نشد"; break;
                    case USER_CANCELED:   errorMessage = "پرداخت توسط کاربر متوقف شد"; break;
                    case NOT_ENOUGH_DATA: errorMessage = "اطلاعات پرداخت کافی نیست"; break;
                    case UNKNOWN:         errorMessage = "خطای ناشناخته"; break;
                }
                Log.wtf("TAG", "ERROR: " + errorMessage);
            }
        });

[حمایت مالی از سازنده پلاگین] (https://2nate.com/pays/create/user/1637) alt text

About

Library to use ZarinPal payment service in android apps

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages