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:
- Download and add this jar file into your project as a library:
- Copy jar file in project-directory/app/libs/
- Right click on file in Android Studio and click on Add as library
- Add our payment Activity to your project manifest file as shown below:
<application>
.
.
.
<activity android:name="ir.moslem_deris.apps.zarinpal.PaymentActivity"/>
.
.
.
</application>
- Add Internet permission to your manifest file (for android 5 and below):
<uses-permission android:name="android.permission.INTERNET"/>
- 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("[email protected]") // 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)