{"id":25588365,"url":"https://github.com/zarinpal/ios-sdk","last_synced_at":"2025-04-12T21:51:45.574Z","repository":{"id":47083362,"uuid":"372799380","full_name":"ZarinPal/iOS-SDK","owner":"ZarinPal","description":"ZarinPal iOS Client in-App Billing","archived":false,"fork":false,"pushed_at":"2022-05-24T08:46:23.000Z","size":153089,"stargazers_count":7,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-03-26T16:01:36.891Z","etag":null,"topics":["ios","payment","payment-gateway","payment-sdk","swift","zarinpal","zarinpal-gateway","zarinpal-ios","zarinpal-payment-service"],"latest_commit_sha":null,"homepage":"https://www.zarinpal.com","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZarinPal.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-01T11:05:51.000Z","updated_at":"2023-09-30T19:42:57.000Z","dependencies_parsed_at":"2022-09-24T22:51:55.851Z","dependency_job_id":null,"html_url":"https://github.com/ZarinPal/iOS-SDK","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZarinPal%2FiOS-SDK","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZarinPal%2FiOS-SDK/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZarinPal%2FiOS-SDK/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZarinPal%2FiOS-SDK/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZarinPal","download_url":"https://codeload.github.com/ZarinPal/iOS-SDK/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248637832,"owners_count":21137538,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","payment","payment-gateway","payment-sdk","swift","zarinpal","zarinpal-gateway","zarinpal-ios","zarinpal-payment-service"],"created_at":"2025-02-21T08:35:36.685Z","updated_at":"2025-04-12T21:51:45.539Z","avatar_url":"https://github.com/ZarinPal.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ZarinPal In App Billing - Purchase SDK | MPG\n\nZarinPal Purchase SDK Provides payment methods on your iOS Application.\n\n\n\n\u003cp align=\"center\" width=\"100%\"\u003e\n\u003cimg src=\"https://avatars.githubusercontent.com/u/13906725?s=200\u0026v=4\" alt=\"ZarinPal Logo\"/\u003e\n\u003c/p\u003e\n\n\n# Requirements\n\n- iOS 11.0+\n- Xcode 12+\n- Swift 5.1+\n\n# Installation\n\nCocoaPods:\n\nCreate Podfile and add ```pod 'ZarinPal'``` and ```ZarinPal_MPG```:\n\n```\nuse_frameworks!\n\ntarget 'YourApp' do\n     pod 'ZarinPal', '~\u003e 1.1.18'\n     pod 'ZarinPal_MPG', '~\u003e 1.1.18'\nend\n```\n\nInstall pods:\n\n```\npod install\n```\nor\n```\npod install --repo-update\n```\n\n# How to use\n###### Step 1\n\n```Swift\nimport ZarinPal\n\n```\n\n###### Step 2\n\nFor `purchase` you need a `ZarinPalBillingClient` instance, `newBuilder` has two type of Payment:\n\n*   as **Payment Request** by `Purchase.newBuilder().asPaymentRequest()`\n*   as **Authority ID** by `Purchase.newBuilder().asAuthority()`\n*   as **SKU** by `Purchase.newBuilder().asSku()`\n\nIf you would create payment Authority on Client, You must use `Purchase.newBuilder().asPayementRequest()`, this method needs below parameters:\n\n**Require Parameters:**\n\n*   Merchant ID: An unique ID of your business payment gateway [ZarinPal Panel](https://next.zarinpal.com/panel/dashboard)\n*   Amount: Amount of Purchase.\n*   Callback URL: A valid `URI` or `URL` Address for sending result purchase.\n*   Description: A Content for showing payer.\n\n[ZarinPal Docs](https://docs.zarinpal.com/paymentGateway/)\n\n**Optional Parameters:**\n\n*   Mobile: Valid Mobile number of payer.\n*   Email: Valid Email Address of payer.\n\n\nCreate payment request:\nyou can add custom URL Schema or your domain: [Docs](https://developer.apple.com/documentation/xcode/defining-a-custom-url-scheme-for-your-app)\n\n\n```Swift\n   let callbackURL = \"https://www.your_domain.com/payment\" // or mycustomschema://my.app.payment\n   let purchase = Purchase.newBuilder()\n                    .asPaymentRequest(merchantID: \"YOUR MERCHANT ID\", amount: 10000, callbackURL: callbackURL, description: \"Test Description for this payment\")\n                    .setType(type: .SHETAB) // or .ALL\n                    .build()\n```\nOr\n\nMaybe You got `Authority` from your server, here You must use `Purchase.newBuilder().asAuthority()`\n```Swift\n    let purchase = Purchase.newBuilder()\n    .asAuthority(\"AUTHORITY\")\n    .build()\n```   \n\n###### Step 3\n\nAdd payment delegate in your viewController also add methods:\n\n```Swift\nclass MyViewController: UIViewController,PaymentDelegate {\n\n      override func viewDidLoad() {\n        super.viewDidLoad()\n        // Do any additional setup after loading the view.\n      }\n\n\n      func didClose() {\n          print(\"did close\")\n      }\n\n      func didException(exception: NSException) {\n          print(\"exception : \\(exception.description)\")\n      }\n\n      func didReceive(receipt: [String:Any]?, raw: String?) {\n          print(\"receipt : \\(String(describing: receipt)) | raw : \\(String(describing: raw)) \")\n      }\n}\n```\n\n###### Step 4\n\nCreate ZarinPal Class and pass payment request and delegate:\n\n```Swift\n     let zarinPal = ZarinPalBillingClient.newBuilder(viewController: self)\n            .setDelegate(self)\n            .build()\n\n      let purchase = Purchase.newBuilder()\n            .asSku(id: \"YOUR PRODUCT ID\")\n            .setType(type: .SHETAB)\n            .build()\n\n     zarinPal.launchBillingFlow(purchase: purchase)\n```\n\nComplete sample code:\n\n```Swift\nimport UIKit\nimport ZarinPal\n\nclass ViewController: UIViewController,PaymentDelegate {\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        // Do any additional setup after loading the view.\n    }\n\n    @IBAction func btn(_ sender: Any) {\n\n          let callbackURL = \"https://www.your_domain.com/payment\" // or mycustomschema://my.app.payment\n\n          let purchase = Purchase.newBuilder()\n                    .asPaymentRequest(merchantID: \"YOUR MERCHANT ID\", amount: 10000, callbackURL: callbackURL, description: \"Test Description for this payment\")\n                    .setType(type: .SHETAB) // or .ALL\n                    .build()\n\n  //let purchase = Purchase.newBuilder()\n  //          .asSku(id: \"377443\")\n  //          .setType(type: .SHETAB)\n  //          .build()\n\n        let zarinPal = ZarinPalBillingClient.newBuilder(viewController: self)\n            .setDelegate(self)\n            .build()\n\n        zarinPal.launchBillingFlow(purchase: purchase)\n\n    }\n\n\n      func didClose() {\n          print(\"did close\")\n      }\n\n      func didException(exception: NSException) {\n          print(\"exception : \\(exception.description)\")\n      }\n\n      func didReceive(receipt: [String:Any]?, raw: String?) {\n        print(\"receipt : \\(String(describing: receipt)) | raw : \\(String(describing: raw)) \")\n      }\n\n\n}\n\n\n```\n\n\nAnd you can get user last purchaes with call query for mobile, cardpan and user email:\n\n```Swift\n        let skus = [\"PRODUCT ID\"]\n\n        let skuParams = SkuQueryParams.newBuilder(merchantID: \"MERCHANT CODE\")\n            .setSkuList(skus)\n            .orderByMobile(\"MOBILE\")\n            .orderByCardPan(\"CARD PAN\")\n            .build()\n\n        let zarinPal = ZarinPalBillingClient.newBuilder(viewController: self)\n            .setDelegate(self)\n            .build()\n\n        zarinPal.querySkuPurchased(query: skuParams) { purchase in\n            purchase?.forEach({ skuPurchased in\n                print(skuPurchased.authority)\n            })\n\n        }\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzarinpal%2Fios-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzarinpal%2Fios-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzarinpal%2Fios-sdk/lists"}