Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

ZarinPal Android Client in-App Billing

NotificationsYou must be signed in to change notification settings

ZarinPal/Android-SDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZarinPal Purchase SDK Provides payment methods on your Android Application.Java Readme here if You want to develop it.

Introduction

ZarinPal in-app purchases are the simplest solution to selling digital products or content on Android apps. So many app developers who want to sell digital goods or offer premium membership to users can simply use the it, in-app billing process for smooth and easy checkouts.

sample

Requirements

  • Android 5.0 (API level 21) and above
  • Android Gradle Plugin 3.5.1
  • Gradle 5.4.1+
  • AndroidX (as of v11.0.0)

Installation

Step 1

Add this to your root build.gradle at the end of repositories.

allprojects {      ext.zarinpalSdkVersion= (LATEST_VERSION_REALEASE)//inform of Releases: https://github.com/ZarinPal/Android-SDK/releases      repositories {...        mavenCentral()     }

Step 2

Add the dependency:

dependencies {      implementation'com.zarinpal:payment-provider:ext.zarinpalSdkVersion'    }

If your project and business trusted to ZarinPal, SDK ables to providingMobile Payment Gateway on your App so You should add theMPG dependency:

dependencies {      implementation'com.zarinpal:payment-provider:ext.zarinpalSdkVersion'      implementation'com.zarinpal:mpg:ext.zarinpalSdkVersion'    }

How to use

  • add Permissions in yourManifest.xml:
   <uses-permissionandroid:name="android.permission.INTERNET"/>   <uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE"/>

Initialize the billing client

Step 1

  • ZarinPalClientBilling provides to create the billing client instance:
val client=ZarinPalBillingClient.newBuilder(this)            .enableShowInvoice()            .setListener(stateListener)            .setNightMode(AppCompatDelegate.MODE_NIGHT_YES)            .build()privateval stateListener=object:BillingClientStateListener {overridefunonClientSetupFinished(state:ClientState) {//Observing client states            }overridefunonClientServiceDisconnected() {Log.v("TAG_INAPP","Billing client Disconnected")//When Service disconnect            }        }

Step 2

For start purchase you need aPurchase instance,Purchase has 3 type of Payment:

  • asPayment Request byasPaymentRequest()
  • asAuthority ID byasAuthority()
  • asSku ID byasSku()

If you would create payment Authority on Client, You must useasPayementRequest(), this method needs below parameters:

Require Parameters:

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

Optional Parameters:

  • Mobile: Valid Mobile number of payer.
  • Email: Valid Email Address of payer.
val purchase=Purchase.newBuilder()            .asPaymentRequest("MERCHANT_ID",1000,"http:\\YOUR_SEVER_URL.com","1000IRR Purchase"            ).build()

Maybe You hadAuthority, here You must useasAuthority()

val purchase=Purchase .newBuilder()            .asAuthority("AUTHORITY_RESOLVED")            .build()

forSku purchase:

val purchase=Purchase.newBuilder()            .asSku("SKU_ID")// SKU_ID is an Id that you've generated on ZarinPal panel.            .build()

Step 3

You must callpurchase method to begin flow payment:

        client.launchBillingFlow(purchase,object:FutureCompletionListener<Receipt> {overridefunonComplete(task:TaskResult<Receipt>) {if (task.isSuccess) {val receipt= task.successLog.v("ZP_RECEIPT", receipt?.transactionID)//here you can send receipt data to your server//sentToServer(receipt)                                    }else {                    task.failure?.printStackTrace()                }            }        })

Step 4

Finally if your eligible to have payment process throughMPG You should addingusesCleartextTraffic to application tag in yourManifest.xml

               <applicationandroid:name="..."android:usesCleartextTraffic="true"            ....            \>

SKU Query

The ZarinPal Library stores the query results in a List of SkuPurchased objects. You can then callquerySkuPurchased and you appear sku purchased with inforamtion in your view and provide service.

val skuQuery=SkuQueryParams.newBuilder("MERCHANT_ID")            .setSkuList(listOf("SKU_ID_000","SKU_ID_001"))            .orderByMobile("0935******")            .build()                            client.querySkuPurchased(skuQuery,object:FutureCompletionListener<List<SkuPurchased>> {overridefunonComplete(task:TaskResult<List<SkuPurchased>>) {if (task.isSuccess){val skuPurchaseList= task.success                    skuPurchaseList?.forEach {Log.v("ZP_SKU_PURCHASED","${it.authority}${it.productId}")                    }                }else{                    task.failure?.printStackTrace()                }            }        })

KTX

a Kotlin extensions for the ZarinPal SDK for Android and Utility Library. These extensions provide Kotlin language features inCoroutines async method:

dependencies {      implementation'com.zarinpal:payment-provider-ktx:ext.zarinpalSdkVersion'    }

and to invokepurchase suspendable method in coroutine scope to start purchase flow:

CoroutineScope(Dispatchers.IO).launch {try {val receipt= client.launchBillingFlow(purchase)Log.v("ZP_RECEIPT", receipt.transactionID)            }catch (ex:Exception) {                ex.printStackTrace()            }        }

invokequerySkuPurchasedsuspendable method in coroutine scope to start purchase flow:

CoroutineScope(Dispatchers.IO).launch {try {val skuPurchaseList= client.querySkuPurchased(skuQuery)                skuPurchaseList?.forEach {Log.v("ZP_SKU_PURCHASED","${it.authority}${it.productId}")                }            }catch (ex:Exception) {                ex.printStackTrace()            }        }

Contract

A contract is a middlware between ZarinPal SDK and your server that provides a new payment provider as credit or digital wallet.

dependencies {      implementation'com.zarinpal:contract:ext.zarinpalSdkVersion'    }

Features

Dark Mode

    client.setNightMode(AppCompatDelegate.MODE_NIGHT_YES)

Appear Invoice

    client.enableShowInvoice()

Releases

  • The Changelog provides a summary of changes in each release

  • The migration guide provides instructions on upgrading from old SDK.

Proguard

The ZarinPal Android SDK will configure your app’s procured (ruls or text file link)

Developed By

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


[8]ページ先頭

©2009-2025 Movatter.jp