Giter VIP home page Giter VIP logo

ios-sdk's Introduction

ZarinPal In App Billing - Purchase SDK | MPG

ZarinPal Purchase SDK Provides payment methods on your iOS Application.

ZarinPal Logo

Requirements

  • iOS 11.0+
  • Xcode 12+
  • Swift 5.1+

Installation

CocoaPods:

Create Podfile and add pod 'ZarinPal' and ZarinPal_MPG:

use_frameworks!

target 'YourApp' do
     pod 'ZarinPal', '~> 1.1.18'
     pod 'ZarinPal_MPG', '~> 1.1.18'
end

Install pods:

pod install

or

pod install --repo-update

How to use

Step 1
import ZarinPal
Step 2

For purchase you need a ZarinPalBillingClient instance, newBuilder has two type of Payment:

  • as Payment Request by Purchase.newBuilder().asPaymentRequest()
  • as Authority ID by Purchase.newBuilder().asAuthority()
  • as SKU by Purchase.newBuilder().asSku()

If you would create payment Authority on Client, You must use Purchase.newBuilder().asPayementRequest(), this method needs below parameters:

Require Parameters:

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

ZarinPal Docs

Optional Parameters:

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

Create payment request: you can add custom URL Schema or your domain: Docs

   let callbackURL = "https://www.your_domain.com/payment" // or mycustomschema://my.app.payment
   let purchase = Purchase.newBuilder()
                    .asPaymentRequest(merchantID: "YOUR MERCHANT ID", amount: 10000, callbackURL: callbackURL, description: "Test Description for this payment")
                    .setType(type: .SHETAB) // or .ALL
                    .build()

Or

Maybe You got Authority from your server, here You must use Purchase.newBuilder().asAuthority()

    let purchase = Purchase.newBuilder()
    .asAuthority("AUTHORITY")
    .build()
Step 3

Add payment delegate in your viewController also add methods:

class MyViewController: UIViewController,PaymentDelegate {

      override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
      }


      func didClose() {
          print("did close")
      }

      func didException(exception: NSException) {
          print("exception : \(exception.description)")
      }

      func didReceive(receipt: [String:Any]?, raw: String?) {
          print("receipt : \(String(describing: receipt)) | raw : \(String(describing: raw)) ")
      }
}
Step 4

Create ZarinPal Class and pass payment request and delegate:

     let zarinPal = ZarinPalBillingClient.newBuilder(viewController: self)
            .setDelegate(self)
            .build()

      let purchase = Purchase.newBuilder()
            .asSku(id: "YOUR PRODUCT ID")
            .setType(type: .SHETAB)
            .build()

     zarinPal.launchBillingFlow(purchase: purchase)

Complete sample code:

import UIKit
import ZarinPal

class ViewController: UIViewController,PaymentDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }

    @IBAction func btn(_ sender: Any) {

          let callbackURL = "https://www.your_domain.com/payment" // or mycustomschema://my.app.payment

          let purchase = Purchase.newBuilder()
                    .asPaymentRequest(merchantID: "YOUR MERCHANT ID", amount: 10000, callbackURL: callbackURL, description: "Test Description for this payment")
                    .setType(type: .SHETAB) // or .ALL
                    .build()

  //let purchase = Purchase.newBuilder()
  //          .asSku(id: "377443")
  //          .setType(type: .SHETAB)
  //          .build()

        let zarinPal = ZarinPalBillingClient.newBuilder(viewController: self)
            .setDelegate(self)
            .build()

        zarinPal.launchBillingFlow(purchase: purchase)

    }


      func didClose() {
          print("did close")
      }

      func didException(exception: NSException) {
          print("exception : \(exception.description)")
      }

      func didReceive(receipt: [String:Any]?, raw: String?) {
        print("receipt : \(String(describing: receipt)) | raw : \(String(describing: raw)) ")
      }


}

And you can get user last purchaes with call query for mobile, cardpan and user email:

        let skus = ["PRODUCT ID"]

        let skuParams = SkuQueryParams.newBuilder(merchantID: "MERCHANT CODE")
            .setSkuList(skus)
            .orderByMobile("MOBILE")
            .orderByCardPan("CARD PAN")
            .build()

        let zarinPal = ZarinPalBillingClient.newBuilder(viewController: self)
            .setDelegate(self)
            .build()

        zarinPal.querySkuPurchased(query: skuParams) { purchase in
            purchase?.forEach({ skuPurchased in
                print(skuPurchased.authority)
            })

        }

ios-sdk's People

Contributors

farshidroohi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

ios-sdk's Issues

ZarinPal/ShetabViewController.swift:142

after app enters foreground from payment safari page
error given
ZarinPal/ShetabViewController.swift:142: Fatal error: Unexpectedly found nil while unwrapping an Optional valu
Screen Shot 1401-01-08 at 19 07 26
e

callbackURL not work v1.1.16 & v1.1.17-beta

a few days ago, payment using safari, callbackURL worked.
recently using in app payment page, callbackURL doesnt work & i manual request again.

one question ty if saying @FarshidRoohi :
in back service, set which method (in app or in safari) working? its interesting

return to app in real device

hi
while payment success done and back to app, method didException(exception: NSException) called and write "unknown error" in real device.
in the simulator everythink is ok.

WhatsApp Image 2022-04-24 at 6 24 05 PM

Task list

  • Add Coupon
  • #2
  • Check Button title alignment in small devices
  • Test MPG
  • Improve Dark mode
  • Purchase type(all, shetab)
  • Change didReceive params to dictionary and raw value
  • Publish new version ๐ŸŽ‰

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.