├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.MD
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zarinpal
│ │ └── ewallets
│ │ └── purchasesdk
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zarinpal
│ │ │ └── ewallets
│ │ │ └── purchasesdk
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable
│ │ └── img.png
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── zarinpal
│ └── ewallets
│ └── purchasesdk
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── purchase
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zarinpal
│ │ └── ewallets
│ │ └── purchase
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zarinpal
│ │ │ └── ewallets
│ │ │ └── purchase
│ │ │ ├── HttpQueue.java
│ │ │ ├── HttpRequest.java
│ │ │ ├── HttpRequestListener.java
│ │ │ ├── OnCallbackRequestPaymentListener.java
│ │ │ ├── OnCallbackVerificationPaymentListener.java
│ │ │ ├── Payment.java
│ │ │ ├── PaymentRequest.java
│ │ │ ├── SandboxPaymentRequest.java
│ │ │ ├── VerificationPayment.java
│ │ │ └── ZarinPal.java
│ └── res
│ │ └── values
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── zarinpal
│ └── ewallets
│ └── purchase
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | xmlns:android
14 |
15 | ^$
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | xmlns:.*
25 |
26 | ^$
27 |
28 |
29 | BY_NAME
30 |
31 |
32 |
33 |
34 |
35 |
36 | .*:id
37 |
38 | http://schemas.android.com/apk/res/android
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | .*:name
48 |
49 | http://schemas.android.com/apk/res/android
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | name
59 |
60 | ^$
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | style
70 |
71 | ^$
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 | .*
81 |
82 | ^$
83 |
84 |
85 | BY_NAME
86 |
87 |
88 |
89 |
90 |
91 |
92 | .*
93 |
94 | http://schemas.android.com/apk/res/android
95 |
96 |
97 | ANDROID_ATTRIBUTE_ORDER
98 |
99 |
100 |
101 |
102 |
103 |
104 | .*
105 |
106 | .*
107 |
108 |
109 | BY_NAME
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
23 |
24 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | Android
51 |
52 |
53 | Android > Lint > Correctness
54 |
55 |
56 | Android > Lint > Performance
57 |
58 |
59 | CorrectnessLintAndroid
60 |
61 |
62 | General
63 |
64 |
65 | LintAndroid
66 |
67 |
68 |
69 |
70 | Android
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.MD:
--------------------------------------------------------------------------------
1 | # The Repo and Project has been DEPRECATED and Archived please check [Android-SDK](https://github.com/ZarinPal/Android-SDK)
2 |
3 | # ZarinPal Purchase Android SDK
4 |
5 | ZarinPal Payment Requeset SDK on Android Platforms
6 | Simply Request to ZarinPal IPG and Callback Handling
7 |
8 |
9 | ### ZarinPal Flow:
10 | 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`
11 |
12 | **What is `Payment Request`?**
13 |
14 | Payment Request is require paramaters payment for Indentity in ZarinPal
15 |
16 | **Require Parameters:**
17 |
18 | * Merchant id: An unique ID of your business payment gateway.
19 | * Amount: Amount of Purchase.
20 | * Callback URL: A valid `URI` or `URL` Address for sending result purchase.
21 | * Description: A Content for showing to payer.
22 |
23 | **Optional Parameters:**
24 |
25 | * Mobile: Valid Mobile number of payer.
26 | * Email: Valid Email Address of payer.
27 |
28 | 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).
29 | 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.
30 | 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.
31 |
32 | 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.
33 |
34 | >Note: ZarinPal is not IAB or IAP, ZarinPal JUST provides payment solution.
35 |
36 |
37 | How to use
38 | ==========
39 |
40 |
41 | - Compile ZarinPal In App Purchase SDK:
42 | ```Gradle
43 | implementation 'com.zarinpal:purchase:0.0.10'
44 | ```
45 | - Internet Access Permission on `AndroidManifest.xml`:
46 |
47 | ```XML
48 |
49 | ```
50 | - Set Your Application Scheme on `AndroidManifest.xml` to Callback for inner handling in App:
51 | ```XML
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | ```
61 | >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.
62 |
63 | ### Example For Payment Request:
64 | ```Java
65 | ZarinPal purchase = ZarinPal.getPurchase(this);
66 | PaymentRequest payment = ZarinPal.getPaymentRequest();
67 | //If you will test on our sandbox, you can use it:
68 | PaymentRequest payment = ZarinPal.getSandboxPaymentRequest();
69 |
70 |
71 |
72 | payment.setMerchantID("71c705f8-bd37-11e6-aa0c-000c295eb8fc");
73 | payment.setAmount(100);
74 | payment.isZarinGateEnable(true); // If you actived `ZarinGate`, can handle payment by `ZarinGate`
75 | payment.setDescription("In App Purchase Test SDK");
76 | payment.setCallbackURL("yourapp://app"); /* Your App Scheme */
77 | payment.setMobile("09355106005"); /* Optional Parameters */
78 | payment.setEmail("imannamix@gmail.com"); /* Optional Parameters */
79 |
80 |
81 | purchase.startPayment(payment, new OnCallbackRequestPaymentListener() {
82 | @Override
83 | public void onCallbackResultPaymentRequest(int status, String authority, Uri paymentGatewayUri, Intent intent) {
84 |
85 |
86 | if (status == 100) {
87 | /*
88 | When Status is 100 Open Zarinpal PG on Browser
89 | */
90 | startActivity(intent);
91 | } else {
92 | Toast.makeText(getApplicationContext(), "Your Payment Failure :(", Toast.LENGTH_LONG).show();
93 | }
94 |
95 | }
96 | });
97 | ```
98 |
99 |
100 | ### Example For Callback Handler:
101 | ```Java
102 | /**
103 | * When User Return to Application From IPG on Browser
104 | */
105 | Uri data = getIntent().getData();
106 | ZarinPal.getPurchase(this).verificationPayment(data, new OnCallbackVerificationPaymentListener() {
107 | @Override
108 | public void onCallbackResultVerificationPayment(boolean isPaymentSuccess, String refID, PaymentRequest paymentRequest) {
109 |
110 |
111 | if (isPaymentSuccess) {
112 | /* When Payment Request is Success :) */
113 | String message = "Your Payment is Success :) " + refID;
114 | Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
115 | } else {
116 | /* When Payment Request is Failure :) */
117 | String message = "Your Payment is Failure :(";
118 | Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
119 | }
120 |
121 |
122 | }
123 | });
124 |
125 | ```
126 |
127 | ### New Options:
128 |
129 | * Support ZarinGate in 0.0.4 Version
130 | * Implemented SandBox Payment in 0.0.8 Version
131 | * `ZarinGate` is Optional attribute in 0.0.10 Version
132 |
133 |
134 |
135 | Developed By
136 | ============
137 |
138 | The Product developed by ZarinPal Team also You can Communicate and open issue
139 | >Note: This version is open source then you can open pull request and we check it, If project
140 | need to your change, We will certainly merge it.
141 |
142 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 29
5 | buildToolsVersion '26.0.3'
6 |
7 | lintOptions {
8 | abortOnError false
9 | }
10 | defaultConfig {
11 | multiDexEnabled true
12 | }
13 |
14 | dexOptions {
15 | javaMaxHeapSize "4g"
16 | }
17 | defaultConfig {
18 | applicationId "com.zarinpal.ewallets.purchasesdk"
19 | minSdkVersion 15
20 | targetSdkVersion 29
21 | versionCode 1
22 | versionName "1.0"
23 | }
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 | testImplementation 'junit:junit:4.12'
35 | implementation 'com.android.support:appcompat-v7:28.0.0'
36 |
37 | // implementation 'com.zarinpal:purchase:0.0.9'
38 |
39 |
40 | implementation project (":purchase")
41 |
42 |
43 |
44 | // compile project(path: ':purchase')
45 | }
46 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Library/Android SDK/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zarinpal/ewallets/purchasesdk/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchasesdk;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zarinpal/ewallets/purchasesdk/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchasesdk;
2 |
3 |
4 | import android.content.Intent;
5 | import android.net.Uri;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.os.Bundle;
8 | import android.util.Log;
9 | import android.view.View;
10 | import android.widget.Button;
11 |
12 | import com.zarinpal.ewallets.purchase.OnCallbackRequestPaymentListener;
13 | import com.zarinpal.ewallets.purchase.OnCallbackVerificationPaymentListener;
14 | import com.zarinpal.ewallets.purchase.PaymentRequest;
15 | import com.zarinpal.ewallets.purchase.ZarinPal;
16 |
17 |
18 | public class MainActivity extends AppCompatActivity {
19 |
20 | @Override
21 | protected void onCreate(Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | setContentView(R.layout.activity_main);
24 |
25 | if (getIntent().getData() != null) {
26 |
27 | ZarinPal.getPurchase(this).verificationPayment(getIntent().getData(), new OnCallbackVerificationPaymentListener() {
28 | @Override
29 | public void onCallbackResultVerificationPayment(boolean isPaymentSuccess, String refID, PaymentRequest paymentRequest) {
30 | Log.i("TAG", "onCallbackResultVerificationPayment: " + refID);
31 | }
32 | });
33 | }
34 |
35 | Button btnPay = (Button) findViewById(R.id.btnPayment);
36 | btnPay.setOnClickListener(new View.OnClickListener() {
37 | @Override
38 | public void onClick(View view) {
39 |
40 |
41 | PaymentRequest payment = ZarinPal.getSandboxPaymentRequest();
42 |
43 |
44 | payment.setMerchantID("71c705f8-bd37-11e6-aa0c-000c295eb8fc");
45 | payment.setAmount(120);
46 | payment.setDescription("In App Purchase Test SDK");
47 | payment.setCallbackURL("app://app");
48 | payment.setMobile("09355106005");
49 | payment.setEmail("imannamix@gmail.com");
50 | payment.isZarinGateEnable(false);
51 |
52 |
53 | ZarinPal.getPurchase(getApplicationContext()).startPayment(payment, new OnCallbackRequestPaymentListener() {
54 | @Override
55 | public void onCallbackResultPaymentRequest(int status, String authority, Uri paymentGatewayUri, Intent intent) {
56 |
57 | startActivity(intent);
58 | }
59 | });
60 |
61 | }
62 | });
63 |
64 |
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZarinPal-Lab/Android-SDK-Payment/64889146d04c9d93190d0ee0c32ca7d77d183f55/app/src/main/res/drawable/img.png
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
19 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZarinPal-Lab/Android-SDK-Payment/64889146d04c9d93190d0ee0c32ca7d77d183f55/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZarinPal-Lab/Android-SDK-Payment/64889146d04c9d93190d0ee0c32ca7d77d183f55/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZarinPal-Lab/Android-SDK-Payment/64889146d04c9d93190d0ee0c32ca7d77d183f55/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZarinPal-Lab/Android-SDK-Payment/64889146d04c9d93190d0ee0c32ca7d77d183f55/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZarinPal-Lab/Android-SDK-Payment/64889146d04c9d93190d0ee0c32ca7d77d183f55/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Purchase SDK
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zarinpal/ewallets/purchasesdk/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchasesdk;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 |
4 | buildscript {
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.5.3'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
13 |
14 |
15 | // NOTE: Do not place your application dependencies here; they belong
16 | // in the individual module build.gradle files
17 | }
18 | }
19 |
20 | allprojects {
21 | repositories {
22 | google()
23 | jcenter()
24 | }
25 | }
26 |
27 | apply plugin: 'com.jfrog.bintray'
28 |
29 |
30 | task clean(type: Delete) {
31 | delete rootProject.buildDir
32 | }
33 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ZarinPal-Lab/Android-SDK-Payment/64889146d04c9d93190d0ee0c32ca7d77d183f55/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Jan 01 11:37:15 IRST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/purchase/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/purchase/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.jfrog.bintray'
3 | apply plugin: 'com.github.dcendents.android-maven'
4 |
5 |
6 |
7 |
8 | android {
9 | compileSdkVersion 29
10 | buildToolsVersion '29.0.2'
11 |
12 | lintOptions {
13 | abortOnError false
14 | }
15 |
16 | defaultConfig {
17 | minSdkVersion 15
18 | targetSdkVersion 29
19 | versionCode 10
20 | versionName "0.0.10"
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 |
29 | }
30 |
31 |
32 |
33 | version = android.defaultConfig.versionName
34 | group = "com.zarinpal"
35 |
36 |
37 |
38 |
39 | task generateSourcesJar(type: Jar) {
40 | from android.sourceSets.main.java.srcDirs
41 | classifier 'sources'
42 | }
43 |
44 | task generateJavadocs(type: Javadoc) {
45 | source = android.sourceSets.main.java.srcDirs
46 | classpath += project.files(android.getBootClasspath()
47 | .join(File.pathSeparator))
48 | }
49 |
50 | task generateJavadocsJar(type: Jar) {
51 | from generateJavadocs.destinationDir
52 | classifier 'javadoc'
53 | }
54 |
55 |
56 |
57 | artifacts {
58 | archives generateJavadocsJar
59 | archives generateSourcesJar
60 | }
61 |
62 |
63 |
64 |
65 | bintray {
66 | Properties properties = new Properties()
67 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
68 | def token = properties["TOKEN"]
69 | def id = properties["USER"]
70 |
71 | user = id
72 | key = token
73 | pkg {
74 |
75 | repo = 'purchase'
76 | name = 'pg'
77 |
78 | version {
79 | name = android.defaultConfig.versionName
80 | desc = 'ZarinPal In App Purchase SDK'
81 | released = new Date()
82 | vcsTag = android.defaultConfig.versionName
83 | }
84 |
85 | licenses = ['Apache-2.0']
86 | vcsUrl = ''
87 | websiteUrl = 'www.zarinpal.com'
88 | }
89 | configurations = ['archives']
90 | }
91 |
92 | dependencies {
93 | compile fileTree(dir: 'libs', include: ['*.jar'])
94 | testCompile 'junit:junit:4.12'
95 | provided 'com.android.support:appcompat-v7:28.0.0'
96 | compile 'com.mcxiaoke.volley:library:1.0.19'
97 |
98 | }
99 |
100 | configurations{
101 | all*.exclude group: 'com.android.volley'
102 | }
103 |
104 |
--------------------------------------------------------------------------------
/purchase/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Library/Android SDK/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/purchase/src/androidTest/java/com/zarinpal/ewallets/purchase/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/purchase/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/HttpQueue.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | import android.content.Context;
4 |
5 | import com.android.volley.Request;
6 | import com.android.volley.RequestQueue;
7 | import com.android.volley.toolbox.Volley;
8 |
9 |
10 | /**
11 | * Android ZarinPal In App Purchase SDK Library v0.0.2 Beta Project.
12 | * Created by ImanX on 12/22/16.
13 | * Copyright Alireza Tarazani All Rights Reserved.
14 | */
15 | class HttpQueue {
16 | private static HttpQueue instance;
17 | private static RequestQueue queue;
18 |
19 | public static HttpQueue getInstance(Context context) {
20 | if (instance == null) {
21 | instance = new HttpQueue();
22 | queue = Volley.newRequestQueue(context);
23 | }
24 | return instance;
25 | }
26 |
27 | public void addToRequest(Request request) {
28 | request.setShouldCache(false);
29 | queue.getCache().clear();
30 | queue.add(request);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/HttpRequest.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import com.android.volley.AuthFailureError;
7 | import com.android.volley.DefaultRetryPolicy;
8 | import com.android.volley.NoConnectionError;
9 | import com.android.volley.Request;
10 | import com.android.volley.Response;
11 | import com.android.volley.TimeoutError;
12 | import com.android.volley.VolleyError;
13 | import com.android.volley.toolbox.JsonObjectRequest;
14 | import com.android.volley.toolbox.StringRequest;
15 |
16 | import org.json.JSONException;
17 | import org.json.JSONObject;
18 |
19 | import java.util.HashMap;
20 | import java.util.Map;
21 |
22 |
23 | /**
24 | * Android ZarinPal In App Purchase SDK Library v0.0.2 Beta Project.
25 | * Created by ImanX on 12/22/16.
26 | * Copyright Alireza Tarazani All Rights Reserved.
27 | */
28 | public class HttpRequest implements Response.Listener, Response.ErrorListener {
29 |
30 | private Request request;
31 | private Context context;
32 | private String url;
33 | private int timeOut;
34 | private int requestMethod;
35 | private byte requestType;
36 | private JSONObject jsonObject;
37 | private HttpRequestListener listener;
38 | private Map headers = new HashMap<>();
39 | private Map params = new HashMap<>();
40 |
41 |
42 | public static final int GET = Request.Method.GET; /* Request Method Fields */
43 | public static final int POST = Request.Method.POST; /* Request Method Fields */
44 | public static final int PUT = Request.Method.PUT; /* Request Method Fields */
45 | public static final int DELETE = Request.Method.DELETE; /* Request Method Fields */
46 | public static final byte RAW = 0; /* Request EasyPayType Fields */
47 | public static final byte FROM_DATA = 1; /* Request EasyPayType Fields */
48 | private static final int TIMEOUT_DEFAULT_VALUE = 10 * 1000;
49 | public static final int INTERNET_CONNECTION_ERROR = -100;
50 | public static final int TIMEOUT_ERROR = -101;
51 | public static final int UNKNOWN_ERROR = -102;
52 | private static final String DEFAULT_ERROR = "Http error incorrect.";
53 |
54 | public HttpRequest(Context context, String url) {
55 | this.url = url;
56 | this.context = context;
57 | }
58 |
59 | public HttpRequest setParams(Map params) { /*this method set Parameters for Request Method POST */
60 | this.params = params;
61 | return this;
62 |
63 | }
64 |
65 | public HttpRequest setJson(JSONObject jsonObject) {
66 | this.jsonObject = jsonObject;
67 | return this;
68 | }
69 |
70 | public HttpRequest setHeaders(HashMap headers) {
71 | this.headers = headers;
72 | return this;
73 | }
74 |
75 | public HttpRequest setRequestType(byte RequestType) { /*this method set Request EasyPayType : JSON || STRING */
76 | this.requestType = RequestType;
77 | return this;
78 | }
79 |
80 | public HttpRequest setRequestMethod(int method) { /*this method set Request Method : POST || GET*/
81 | requestMethod = method;
82 | return this;
83 | }
84 |
85 | public HttpRequest setTimeOut(int timeOut) {
86 | this.timeOut = (timeOut * 1000);
87 | return this;
88 | }
89 |
90 | @Override
91 | public void onResponse(Object response) {
92 |
93 | if (!isJsonValid(response)) {
94 | listener.onSuccessResponse(null, response.toString());
95 | return;
96 | }
97 |
98 | try {
99 | listener.onSuccessResponse(new JSONObject(response.toString()), response.toString());
100 | } catch (JSONException e) {
101 | e.printStackTrace();
102 | }
103 | }
104 |
105 | @Override
106 | public void onErrorResponse(VolleyError error) {
107 |
108 | if (error instanceof NoConnectionError) {
109 | listener.onFailureResponse(INTERNET_CONNECTION_ERROR, DEFAULT_ERROR);
110 | return;
111 | }
112 |
113 | if (error instanceof TimeoutError) {
114 | listener.onFailureResponse(TIMEOUT_ERROR, DEFAULT_ERROR);
115 | return;
116 | }
117 |
118 | if (error.networkResponse == null) {
119 | listener.onFailureResponse(UNKNOWN_ERROR, DEFAULT_ERROR);
120 | return;
121 | }
122 |
123 | listener.onFailureResponse(error.networkResponse.statusCode, new String(error.networkResponse.data));
124 |
125 | Log.i("TAG Error HttpRequest", new String(error.networkResponse.data));
126 | }
127 |
128 |
129 | public void get(HttpRequestListener listener) {
130 | this.listener = listener;
131 | if (requestType == FROM_DATA) {
132 |
133 | this.request = new StringRequest(requestMethod, url, this, this) {
134 | @Override
135 | protected Map getParams() throws AuthFailureError {
136 | return params;
137 | }
138 |
139 | @Override
140 | public Map getHeaders() throws AuthFailureError {
141 | return headers;
142 | }
143 | };
144 |
145 | } else {
146 |
147 | this.request = new JsonObjectRequest(requestMethod, url, (jsonObject == null ? new JSONObject(params) : jsonObject), this, this) {
148 | @Override
149 | public Map getHeaders() throws AuthFailureError {
150 | return headers;
151 | }
152 | };
153 | }
154 |
155 | this.request.setRetryPolicy(new DefaultRetryPolicy(
156 | (this.timeOut == 0) ? TIMEOUT_DEFAULT_VALUE : timeOut,
157 | DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
158 | DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
159 |
160 | HttpQueue.getInstance(context).addToRequest(request);
161 |
162 | }
163 |
164 | private boolean isJsonValid(Object object) {
165 | try {
166 | new JSONObject(object.toString());
167 | return true;
168 | } catch (Exception ex) {
169 | return false;
170 | }
171 | }
172 |
173 | }
174 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/HttpRequestListener.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | import org.json.JSONObject;
4 |
5 | /**
6 | * Android ZarinPal In App Purchase SDK Library v0.0.2 Beta Project.
7 | * Created by ImanX on 12/22/16.
8 | * Copyright Alireza Tarazani All Rights Reserved.
9 | */
10 | public interface HttpRequestListener {
11 | void onSuccessResponse(JSONObject jsonObject, String contentResponse);
12 |
13 | void onFailureResponse(int httpStatusCode, String dataError);
14 | }
15 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/OnCallbackRequestPaymentListener.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 |
4 | import android.content.Intent;
5 | import android.net.Uri;
6 |
7 | /**
8 | * Android ZarinPal In App Purchase SDK Library v0.0.2 Beta Project.
9 | * Created by ImanX on 12/22/16.
10 | * Copyright Alireza Tarazani All Rights Reserved.
11 | */
12 | public interface OnCallbackRequestPaymentListener {
13 | void onCallbackResultPaymentRequest(int status,
14 | String authority,
15 | Uri paymentGatewayUri,
16 | Intent intent);
17 | }
18 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/OnCallbackVerificationPaymentListener.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | /**
4 | * Android ZarinPal In App Purchase SDK Library v0.0.2 Beta Project.
5 | * Created by ImanX on 12/22/16.
6 | * Copyright Alireza Tarazani All Rights Reserved.
7 | */
8 | public interface OnCallbackVerificationPaymentListener {
9 | void onCallbackResultVerificationPayment(boolean isPaymentSuccess,
10 | String refID,
11 | PaymentRequest paymentRequest);
12 | }
13 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/Payment.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | /**
4 | * Android ZarinPal In App Purchase SDK Library v0.0.2 Beta Project.
5 | * Created by ImanX on 12/22/16.
6 | * Copyright Alireza Tarazani All Rights Reserved.
7 | */
8 | class Payment {
9 | public static final String MERCHANT_ID_PARAMS = "MerchantID";
10 | public static final String AMOUNT_PARAMS = "Amount";
11 | public static final String DESCRIPTION_PARAMS = "Description";
12 | public static final String CALLBACK_URL_PARAMS = "CallbackURL";
13 | public static final String MOBILE_PARAMS = "Mobile";
14 | public static final String EMAIL_PARAMS = "Email";
15 | public static final String AUTHORITY_PARAMS = "Authority";
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/PaymentRequest.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.annotation.Nullable;
5 |
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | /**
10 | * Android ZarinPal In App Purchase SDK Library v0.0.2 Beta Project.
11 | * Created by ImanX on 12/22/16.
12 | * Copyright Alireza Tarazani All Rights Reserved.
13 | */
14 | public class PaymentRequest {
15 |
16 |
17 | protected static final String PAYMENT_GATEWAY_URL = "https://www.%szarinpal.com/pg/StartPay/%s/%s";
18 | protected static final String PAYMENT_REQUEST_URL = "https://www.%szarinpal.com/pg/rest/WebGate/PaymentRequest.json";
19 | protected static final String VERIFICATION_PAYMENT_URL = "https://www.%szarinpal.com/pg/rest/WebGate/PaymentVerification.json";
20 |
21 |
22 | private String merchantID;
23 | private long amount;
24 | private String mobile;
25 | private String email;
26 | private String description;
27 | private String callBackURL;
28 | private String authority;
29 | private boolean isZarinGateEnable;
30 | private String payload;
31 |
32 | public String getPayload() {
33 | return payload;
34 | }
35 |
36 | public void setPayload(String payload) {
37 | this.payload = payload;
38 | }
39 |
40 | public boolean isZarinGateEnable() {
41 | return isZarinGateEnable;
42 | }
43 |
44 | public void isZarinGateEnable(boolean zarinGateEnable) {
45 | isZarinGateEnable = zarinGateEnable;
46 | }
47 |
48 | public void setMerchantID(String merchantID) {
49 | this.merchantID = merchantID;
50 | }
51 |
52 | public void setCallbackURL(String callBackURL) {
53 | this.callBackURL = callBackURL;
54 | }
55 |
56 | public void setAmount(long amount) {
57 | this.amount = amount;
58 | }
59 |
60 | public void setDescription(String description) {
61 | this.description = description;
62 | }
63 |
64 | public void setMobile(String mobile) {
65 | this.mobile = mobile;
66 | }
67 |
68 | public void setEmail(String email) {
69 | this.email = email;
70 | }
71 |
72 | public String getCallBackURL() {
73 | return callBackURL;
74 | }
75 |
76 | public void setAuthority(String authority) {
77 | this.authority = authority;
78 | }
79 |
80 | public long getAmount() {
81 | return amount;
82 | }
83 |
84 |
85 | public String getDescription() {
86 | return description;
87 | }
88 |
89 |
90 | public String getMobile() {
91 | return mobile;
92 | }
93 |
94 |
95 | public String getMerchantID() {
96 | return merchantID;
97 | }
98 |
99 | public String getEmail() {
100 | return email;
101 | }
102 |
103 | public String getAuthority() {
104 | return authority;
105 | }
106 |
107 | public JSONObject getPaymentRequestAsJson() throws JSONException {
108 | JSONObject jsonObject = new JSONObject();
109 | jsonObject.put(Payment.MERCHANT_ID_PARAMS, getMerchantID());
110 | jsonObject.put(Payment.AMOUNT_PARAMS, getAmount());
111 | jsonObject.put(Payment.DESCRIPTION_PARAMS, getDescription());
112 | jsonObject.put(Payment.CALLBACK_URL_PARAMS, getCallBackURL());
113 | jsonObject.put(Payment.MOBILE_PARAMS, getMobile()); //Optional Value
114 | jsonObject.put(Payment.EMAIL_PARAMS, getEmail());//Optional Value
115 | return jsonObject;
116 | }
117 |
118 | public String getStartPaymentGatewayURL(String authority) {
119 | return String.format(PAYMENT_GATEWAY_URL, "", authority, isZarinGateEnable ? "ZarinGate" : "");
120 | }
121 |
122 | public String getPaymentRequestURL() {
123 | return String.format(PAYMENT_REQUEST_URL, "");
124 | }
125 |
126 | public String getVerificationPaymentURL() {
127 | return String.format(VERIFICATION_PAYMENT_URL, "");
128 | }
129 |
130 |
131 | }
132 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/SandboxPaymentRequest.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | /**
4 | * Created by ImanX.
5 | * PurchaseSDK | Copyrights 2018 ZarinPal Crop.
6 | */
7 |
8 | public class SandboxPaymentRequest extends PaymentRequest {
9 |
10 | private static final String SANDBOX = "sandbox.";
11 | private static final String WORLD_WIDE_WEB = "www.";
12 |
13 | @Override
14 | public String getPaymentRequestURL() {
15 | return String.format(PAYMENT_REQUEST_URL, SANDBOX)
16 | .replace(WORLD_WIDE_WEB, "");
17 | }
18 |
19 | @Override
20 | public String getStartPaymentGatewayURL(String authority) {
21 | return String.format(PAYMENT_GATEWAY_URL, SANDBOX, authority, isZarinGateEnable() ? "ZarinGate" : "")
22 | .replace(WORLD_WIDE_WEB, "");
23 | }
24 |
25 | @Override
26 | public String getVerificationPaymentURL() {
27 | return String.format(VERIFICATION_PAYMENT_URL, SANDBOX)
28 | .replace(WORLD_WIDE_WEB, "");
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/VerificationPayment.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | /**
7 | * Android ZarinPal In App Purchase SDK Library v0.0.2 Beta Project.
8 | * Created by ImanX on 12/22/16.
9 | * Copyright Alireza Tarazani All Rights Reserved.
10 | */
11 | class VerificationPayment {
12 |
13 | private long amount;
14 | private String authority;
15 | private String merchantID;
16 |
17 | public long getAmount() {
18 | return amount;
19 | }
20 |
21 | public void setAmount(long amount) {
22 | this.amount = amount;
23 | }
24 |
25 | public String getAuthority() {
26 | return authority;
27 | }
28 |
29 | public void setAuthority(String authority) {
30 | this.authority = authority;
31 | }
32 |
33 | public String getMerchantID() {
34 | return merchantID;
35 | }
36 |
37 | public void setMerchantID(String merchantID) {
38 | this.merchantID = merchantID;
39 | }
40 |
41 |
42 | public JSONObject getVerificationPaymentAsJson() throws JSONException {
43 | JSONObject object = new JSONObject();
44 | object.put(Payment.AUTHORITY_PARAMS, getAuthority());
45 | object.put(Payment.AMOUNT_PARAMS, getAmount());
46 | object.put(Payment.MERCHANT_ID_PARAMS, getMerchantID());
47 | return object;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/purchase/src/main/java/com/zarinpal/ewallets/purchase/ZarinPal.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.net.Uri;
7 |
8 | import org.json.JSONException;
9 | import org.json.JSONObject;
10 |
11 |
12 | /**
13 | * Android ZarinPal In App Purchase SDK Library v0.0.2 Beta Project.
14 | * Created by ImanX on 12/22/16.
15 | * Copyright Alireza Tarazani All Rights Reserved.
16 | */
17 | @SuppressLint("StaticFieldLeak")
18 | public class ZarinPal {
19 |
20 |
21 | private static ZarinPal instance;
22 | private Context context;
23 | private PaymentRequest paymentRequest;
24 |
25 |
26 | public static ZarinPal getPurchase(Context context) {
27 | if (instance == null) {
28 | instance = new ZarinPal(context);
29 | }
30 | return instance;
31 | }
32 |
33 |
34 | public static PaymentRequest getPaymentRequest() {
35 | return new PaymentRequest();
36 | }
37 |
38 | public static SandboxPaymentRequest getSandboxPaymentRequest() {
39 | return new SandboxPaymentRequest();
40 | }
41 |
42 | private ZarinPal(Context context) {
43 | /* ZarinPal Class blocked create a instance */
44 | this.context = context;
45 | }
46 |
47 | public void verificationPayment(Uri uri, final OnCallbackVerificationPaymentListener listener) {
48 |
49 | if (uri == null || paymentRequest == null || !uri.isHierarchical()) {
50 | return;
51 | }
52 |
53 |
54 | boolean isSuccess = uri.getQueryParameter("Status").equals("OK");
55 | String authority = uri.getQueryParameter("Authority");
56 |
57 | if (!authority.equals(paymentRequest.getAuthority())) {
58 | listener.onCallbackResultVerificationPayment(false, null, paymentRequest);
59 | return;
60 | }
61 |
62 | if (!isSuccess) {
63 | listener.onCallbackResultVerificationPayment(false, null, paymentRequest);
64 | return;
65 | }
66 |
67 |
68 | VerificationPayment verificationPayment = new VerificationPayment();
69 | verificationPayment.setAmount(this.paymentRequest.getAmount());
70 | verificationPayment.setMerchantID(this.paymentRequest.getMerchantID());
71 | verificationPayment.setAuthority(authority);
72 |
73 | try {
74 | new HttpRequest(context, paymentRequest.getVerificationPaymentURL())
75 | .setJson(verificationPayment.getVerificationPaymentAsJson())
76 | .setRequestMethod(HttpRequest.POST)
77 | .setRequestType(HttpRequest.RAW)
78 | .get(new HttpRequestListener() {
79 | @Override
80 | public void onSuccessResponse(JSONObject jsonObject, String contentResponse) {
81 | try {
82 | String refID = jsonObject.getString("RefID");
83 | listener.onCallbackResultVerificationPayment(true, refID, paymentRequest);
84 | } catch (JSONException e) {
85 | e.printStackTrace();
86 | }
87 | }
88 |
89 | @Override
90 | public void onFailureResponse(int httpStatusCode, String dataError) {
91 | listener.onCallbackResultVerificationPayment(false, null, paymentRequest);
92 | }
93 | });
94 |
95 |
96 | } catch (Exception ex) {
97 | ex.printStackTrace();
98 | }
99 | }
100 |
101 | public void startPayment(final PaymentRequest paymentRequest, final OnCallbackRequestPaymentListener listener) {
102 |
103 | this.paymentRequest = paymentRequest;
104 |
105 | try {
106 | new HttpRequest(context, paymentRequest.getPaymentRequestURL())
107 | .setRequestType(HttpRequest.RAW)
108 | .setRequestMethod(HttpRequest.POST)
109 | .setJson(paymentRequest.getPaymentRequestAsJson())
110 | .get(new HttpRequestListener() {
111 | @Override
112 | public void onSuccessResponse(JSONObject jsonObject, String contentResponse) {
113 |
114 | try {
115 | int status = jsonObject.getInt("Status");
116 | String authority = jsonObject.getString("Authority");
117 | paymentRequest.setAuthority(authority);
118 |
119 | // ChromeTab.launch(mContext, URLPaymentBuilder.getAuthorityPaymentURL(authority));
120 |
121 | Uri uri = Uri.parse(paymentRequest.getStartPaymentGatewayURL(authority));
122 | Intent intent = new Intent(Intent.ACTION_VIEW, uri);
123 | listener.onCallbackResultPaymentRequest(status, authority, uri, intent);
124 | } catch (JSONException e) {
125 | e.printStackTrace();
126 | }
127 |
128 | }
129 |
130 | @Override
131 | public void onFailureResponse(int httpStatusCode, String dataError) {
132 |
133 | try {
134 | JSONObject object = new JSONObject(dataError);
135 | int status = object.getInt("Status");
136 | listener.onCallbackResultPaymentRequest(status, null, null, null);
137 | } catch (JSONException e) {
138 | e.printStackTrace();
139 | }
140 |
141 | }
142 | });
143 | } catch (Exception ex) {
144 | ex.printStackTrace();
145 | }
146 | }
147 |
148 | }
149 |
--------------------------------------------------------------------------------
/purchase/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | purchase
3 |
4 |
--------------------------------------------------------------------------------
/purchase/src/test/java/com/zarinpal/ewallets/purchase/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zarinpal.ewallets.purchase;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':purchase'
2 |
--------------------------------------------------------------------------------