Giter Site home page Giter Site logo

zarinpal-lab / android-sdk-payment Goto Github PK

View Code? Open in Web Editor NEW
19.0 9.0 11.0 307 KB

A Simple Library for handle ZarinPal Payment on Android

Java 100.00%
android sdk android-sdk-library zarinpal zarinpal-android-sample pg ipg inapp-billing inapppurchase

android-sdk-payment's Introduction

The Repo and Project has been DEPRECATED and Archived please check Android-SDK

ZarinPal Purchase Android SDK

ZarinPal Payment Requeset SDK on Android Platforms Simply Request to ZarinPal IPG and Callback Handling

ZarinPal Flow:

In first step You must initilize of ZarinPal by getPurchase after that, ZarinPal Ready to Payment. for begining you must create a PaymentRequest by getPaymentRequest, Now you must set parameters MerchantID, Amount (In Rials), Description and CallbackUrl

What is Payment Request?

Payment Request is require paramaters payment for Indentity in ZarinPal

Require Parameters:

  • Merchant id: An unique ID of your business payment gateway.
  • Amount: Amount of Purchase.
  • Callback URL: A valid URI or URL Address for sending result purchase.
  • Description: A Content for showing to payer.

Optional Parameters:

  • Mobile: Valid Mobile number of payer.
  • Email: Valid Email Address of payer.

You send a PaymentRequest for ZarinPal with parameters MerchantID, Amount (In Rials), Description and CallbackUrl . Then ZarinPal will reply to you with a unique purchase ID (Authority). Then with the Authority in Hand, You call startPayment method and ZarinPal in response will direct you to a payment gateway if the purchase ID is valid and after completing the purchase , Zarinpal send Purchase Result to CallbackUrl. After completing the purchase, you can send a verificationPayment request if it is successful, and ZarinPal will send you a RefID, which represents the transaction ID, in case of success.

for verifty purchase you must set getIntent().getData() and call verificationPayment for verify inner app sure ZarinPal don't recommend to use this method becuase this is not safe. That's better you do verifing flow on your server and notify your app.

Note: ZarinPal is not IAB or IAP, ZarinPal JUST provides payment solution.

How to use

  • Compile ZarinPal In App Purchase SDK:
   implementation 'com.zarinpal:purchase:0.0.10'
  • Internet Access Permission on AndroidManifest.xml:
    <uses-permission android:name="android.permission.INTERNET"/>
  • Set Your Application Scheme on AndroidManifest.xml to Callback for inner handling in App:
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>

         <category android:name="android.intent.category.DEFAULT"/>
         <category android:name="android.intent.category.BROWSABLE"/>

         <data android:scheme="<YOUR-APP-SCHEME>"/>
     </intent-filter>

Note: If You want handle and checking of verification your Payment on Your sever you must set your server address (aka URL) by setCallbackURL and no need to do the above step.

Example For Payment Request:

       ZarinPal       purchase = ZarinPal.getPurchase(this);
       PaymentRequest payment  = ZarinPal.getPaymentRequest();
       //If you will test on our sandbox, you can use it:
       PaymentRequest payment  = ZarinPal.getSandboxPaymentRequest();



       payment.setMerchantID("71c705f8-bd37-11e6-aa0c-000c295eb8fc");
       payment.setAmount(100);
       payment.isZarinGateEnable(true);  // If you actived `ZarinGate`, can handle payment by `ZarinGate`
       payment.setDescription("In App Purchase Test SDK");
       payment.setCallbackURL("yourapp://app");     /* Your App Scheme */
       payment.setMobile("09355106005");            /* Optional Parameters */
       payment.setEmail("[email protected]");     /* Optional Parameters */


       purchase.startPayment(payment, new OnCallbackRequestPaymentListener() {
           @Override
           public void onCallbackResultPaymentRequest(int status, String authority, Uri paymentGatewayUri, Intent intent) {


               if (status == 100) {
                   /*
                   When Status is 100 Open Zarinpal PG on Browser
                   */
                   startActivity(intent);
               } else {
                   Toast.makeText(getApplicationContext(), "Your Payment Failure :(", Toast.LENGTH_LONG).show();
               }

           }
       });

Example For Callback Handler:

        /**
        * When User Return to Application From IPG on Browser
        */
        Uri data = getIntent().getData();
       ZarinPal.getPurchase(this).verificationPayment(data, new OnCallbackVerificationPaymentListener() {
           @Override
           public void onCallbackResultVerificationPayment(boolean isPaymentSuccess, String refID, PaymentRequest paymentRequest) {


               if (isPaymentSuccess) {
                   /* When Payment Request is Success :) */
                   String message = "Your Payment is Success :) " + refID;
                   Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
               } else {
                   /* When Payment Request is Failure :) */
                   String message = "Your Payment is Failure :(";
                   Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
               }


           }
       });

New Options:

  • Support ZarinGate in 0.0.4 Version
  • Implemented SandBox Payment in 0.0.8 Version
  • ZarinGate is Optional attribute in 0.0.10 Version

Developed By

The Product developed by ZarinPal Team also You can Communicate and open issue

Note: This version is open source then you can open pull request and we check it, If project need to your change, We will certainly merge it.

android-sdk-payment's People

Contributors

imanx avatar mohammadestk avatar moradi-morteza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

android-sdk-payment's Issues

WebView

سلام .
من میخوام درگاه پرداخت توی وب ویوی اپلیکیشن من باز بشه نه تو مرورگر کاربر ( به خاطر ثبت پرداخت و سفارش ) چطوری میتونم این کار رو انجام بدم ؟

use this sdk not just with activity

hello my friend . i'm a android developer and coding with kotlin .
I use this your sample in my project and change it to kotlin .
the problem is that why this method just work with activities but not with fragments .
it's a good thing if you could do this in fragments not just activity .
thank's to you .

set extra data to payload

how to set extra data to payload and return back it in getPurchase method?
i can use intent but i think its not secure

404 error when using the SandboxPaymentRequest

I am developing an Android app with an in-app purchase feature. I use the Zarinpal library to manage the payments process. To test my code and check the responses from the Zarinpal, I used the SandboxPaymentRequest class, but whenever I call the startPayment method, it returns the -11 status code. When I dived into the startPayment method of the ZarinPal class, I got that it calls the onFailureResponse method with the 404 as the 'httpStatusCode' parameter.
The SandboxPaymentRequest.getPaymentRequestURL() returns the following URL:
https://sandbox.zarinpal.com/pg/rest/WebGate/PaymentRequest.json
This URL doesn't work and always returns the 404.

What is the valid URL of the Sandbox?

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

I'm using 'dev.dworks.libs:volleyplus:0.1.4' library which extended version of android:volley and included actual volley .
after using ZarinPal i got this error :

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

i tried multiDexEnabled ,dexOptions , implementation and excluding volley but none of them worked for me. it's seems you are using extended version of volley too for security reason which that not going work for everyone.
i think you should've changed the 'packageid' so others can use volley.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '26.0.2'

    dexOptions {
        jumboMode true
        javaMaxHeapSize "4g"
    }
    configurations {
        all*.exclude group: 'com.android.volley'
    }
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 11
        versionName "1.11"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.support:support-vector-drawable:26.0.0-alpha1'
    implementation 'com.android.support:support-v4:26.0.0-alpha1'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.google.android.gms:play-services-auth:8.3.0'
    implementation 'com.google.android.gms:play-services-identity:8.3.0'
    implementation 'com.android.support:appcompat-v7:26.+'
    implementation 'com.android.support:design:26.+'
    implementation 'com.android.support.constraint:constraint-layout:1.0.0-alpha8'
    implementation 'dev.dworks.libs:volleyplus:0.1.4'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.mikhaellopez:hfrecyclerview:1.0.0'
    implementation 'com.mobsandgeeks:android-saripaar:2.1.0-SNAPSHOT'
    implementation 'com.zarinpal:purchase:0.0.3-beta'
    implementation 'com.github.bumptech.glide:glide:4.2.0'
    implementation 'com.droidninja:filepicker:2.0.9'
    testCompile 'junit:junit:4.12'
    implementation 'com.android.support:cardview-v7:26.0.0-alpha1'
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.