Papara 5.2.0

Papara 5.2.0

测试已测试
语言语言 SwiftSwift
许可协议 MIT
发布日期上次发布2020年2月
SPM支持SPM

Utku Yıldırımaslanmehmetsalih 维护。



Papara 5.2.0

  • Papara

Papara iOS SDK

CI Status Version License Platform

您可以在 http://www.papara.com 注册一个 Papara 账户。

要求

  • iOS 9.0+
  • Xcode 8.0+
  • Swift 5+

示例

要尝试示例,您需要有 Papara Sandbox iOS App

  1. 从 Testflight 安装 Papara Sandbox iOS App
  2. 将示例应用的 Bundle Identifier 改为您真实的应用包标识符
  3. 将示例应用的 PaparaAppId 从配置文件更改为您的 Papara 应用 ID
  4. 在已预先安装 Papara Sandbox iOS App 的设备上运行 示例应用

安装

CocoaPods

CocoaPods 是 Cocoa 项目的依赖管理器。您可以使用以下命令进行安装

$ gem install cocoapods

Swift 5

要使用 CocoaPods 将 Papara 集成到您的 Xcode 项目中,请在您的 Podfile 中指定它

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'Papara', '~> 5.0'
end

然后,运行以下命令

$ pod install

App Id

您需要获取您的应用程序 Papara 的 app id

使用方法

配置

  • PaparaAppID 将由 Papara 提供
  • PaparaSandbox 如果您想在沙箱环境中进行测试,则设置为 true
  • LSApplicationQueriesSchemes 在生产版本中移除 papara-sandbox
  • CFBundleURLTypes 用于处理从 Papara 应用返回的内容。应为 papara{PaparaAppID}。例如,如果您的 AppId 是 87826504,则 CFBundleURLTypes 将是 papara87826504

在 Xcode 中,对您的项目的 .plist 文件进行右键单击,并选择 Open As -> Source Code。

在文件内容的最后元素之前插入以下 XML 片段

如果您已经有了相同的键,则需要合并它们

<dict>
	...
	<key>PaparaAppID</key>
	<string>87826504</string>
	<key>PaparaSandbox</key>
	<true/>
	<key>LSApplicationQueriesSchemes</key>
	<array>
		<string>papara</string>
		<string>papara-sandbox</string>
	</array>
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>papara87826504</string>
			</array>
		</dict>
	</array>
</dict

初始化

AppDelegate.swift

import Papara

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
	...
    Papara.application(application, didFinishLaunchingWithOptions: launchOptions)
    ...
    return true
}

处理器

Papara如果在SDK中处理了链接,则返回true

AppDelegate.swift

import Papara

func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
    let handled = Papara.application(application, handleOpen: url)
    // Add any custom logic here.
    return handled
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
    let handled = Papara.application(app, open: url, options: options)
    // Add any custom logic here.
    return handled
}

Papara账户号码

UIViewController.swift

import Papara

Papara.getPaparaNumber(self) { (result) in
    switch result {
    case .success(let paparaNumber):
        self.showAlertDialog("Success", message: String(paparaNumber))
    case .fail(let error):
        self.showAlertDialog("Error", message: error.localizedDescription)
    case .cancel:
        self.showAlertDialog("Cancel", message: "Cancel")
    }
}

Papara转账

向Papara号码发送

UIViewController.swift

import Papara

Papara.sendMoney(self, to: .paparaNumber(Int64(wallet)!), amount: amount!) { (result) in
    switch result {
    case .success:
        self.showAlertDialog("Success", message: "Success")
    case .fail(let error):
        self.showAlertDialog("Fail", message: error.localizedDescription)
    case .cancel:
        self.showAlertDialog("Cancel", message: "Cancel")
    }
}

发送到手机

UIViewController.swift

import Papara

Papara.sendMoney(self, to: .mobile(wallet), amount: amount!) { (result) in
    switch result {
    case .success:
        self.showAlertDialog("Success", message: "Success")
    case .fail(let error):
        self.showAlertDialog("Fail", message: error.localizedDescription)
    case .cancel:
        self.showAlertDialog("Cancel", message: "Cancel")
    }
}

发送到电子邮件地址

UIViewController.swift

import Papara

Papara.sendMoney(self, to: .email(wallet), amount: amount!) { (result) in
    switch result {
    case .success:
        self.showAlertDialog("Success", message: "Success")
    case .fail(let error):
        self.showAlertDialog("Fail", message: error.localizedDescription)
    case .cancel:
        self.showAlertDialog("Cancel", message: "Cancel")
    }
}

Papara付款

  • 首先,您需要通过后端创建一个支付。
  • SDK需要从后端获取paymentIdpaymentUrlredirectUrl
UIViewController.swift

import Papara

Papara.pay(self, paymentId: payment.id, paymentUrl: payment.paymentUrl, redirectUrl: payment.redirectUrl) { (result) in
    switch result {
    case .success(let paymentId, let referenceId, let status, let amount):
        self.showAlertDialog("Success", message: "Success")
    case .fail(let error):
        self.showAlertDialog("Error", message: error.localizedDescription)
    case .cancel:
        self.showAlertDialog("Cancel", message: "Cancel")
    }
}

许可

Papara 可在 MIT 许可下使用。有关更多信息,请参阅 LICENSE 文件。