SeerBitCheckout 1.2.9

SeerBitCheckout 1.2.9

SeerBit 维护。



 
依赖
SDWebImage~> 5.18.7
SDWebImageSwiftUI~> 2.2.6
 

  • 作者:
  • SeerBit

seerbit

SeerBit Native Ios SDK

SeerBit Native ios sdk用于无缝集成SeerBit支付网关到原生iOS应用程序。它非常简单且易于集成。完全使用SwiftUI构建,并支持与UIKKit项目集成。

需求

  • 商家必须在SeerBit拥有账户或在中创建一个以开始,并在SeerBit商户仪表板上。
  • 获取商家的有效公钥。

实现

  • 使用以下url通过Swift包管理器将包添加到您的SwiftUI或UIKit项目:
https://github.com/seerbit-developers/SeerBitCheckout
  • 在Swift包管理器将包添加到您的项目后,将SeerBitCheckout导入到您想要使用的文件中。

在项目中配置deep link

  • 使用以下自定义uri scheme将deep link配置添加到项目中:
seerbitioscheckout
  • 添加deep link的最直接方式是在选择项目目标时单击“信息”选项卡。单击URL类型三角形按钮,并将“seerbitioscheckout”粘贴到URL Schemes占位符中。
  • 此sdk适用于iOS 16.0及以上版本。请确保您的项目目标为iOS 16.0及以上。
  • 请注意,如果您的项目已经有了一个url scheme,您仍然需要创建另一个使用上述自定义url scheme。

用法:必须将这些参数提供给开始的struct,InitSeerbitCheckout();

必需

  • 商家的有效公钥 // SBTESTPUBK_t4G16GCA1O51AV0Va3PPretaisXubSw1(这是一个用于测试目的的测试公钥)
  • 金额
  • 客户的姓名
  • 客户的电子邮件
  • 客户的电话号码

可选

  • productId //默认为空字符串
  • vendorId //默认为空字符串
  • 货币 //默认为商家的国家货币
  • 国家 //默认为商家所在国家
  • pocketReference //在需要将资金移入钱包时使用
  • transactionPaymentReference //我们为每次交易生成支付参考,但如果您提供自己的,该sdk将使用它。
  • tokenize //仅在需要将卡标记化时使用 - 默认为false
  • productDescription //默认为空字符串

示例

SwiftUi项目

import SwiftUI
import SeerBitCheckout


struct ContentView: View {
   
   @State private var transactionStatusData: QueryTransactionDataModel? = nil
   
   @State var fullName: String = ""
   @State var publicKey: String = ""
   @State var email: String = ""
   @State var mobileNumber: String = ""
   @State var amount: String = ""
   
   @State var startCheckout = false
   
   
   var body: some View {
       VStack{
           if(startCheckout) {
               InitSeerbitCheckout(
                   amount: amount,
                   fullName:fullName,
                   mobileNumber:mobileNumber,
                   publicKey: publicKey,
                   email:email
               )
           }else{
               VStack{
                   Spacer().frame(height: 30)
                   Image(.checkoutLogo)
                       .resizable()
                       .frame(width: 60, height: 60)
                       .aspectRatio(contentMode: .fit)
                       .clipShape(RoundedRectangle(cornerRadius: 2))
                   Spacer().frame(height: 70)
                   CustomInput(value: $fullName, placeHolder: "Full name")
                   Spacer().frame(height: 30)
                   CustomInput(value: $publicKey, placeHolder: "publicKey")
                   Spacer().frame(height: 30)
                   CustomInput(value: $email, placeHolder: "email")
                   Spacer().frame(height: 30)
                   CustomInput(value: $mobileNumber, placeHolder: "mobileNumber")
                   Spacer().frame(height: 30)
                   CustomInput(value: $amount, placeHolder: "amount")
                   Spacer().frame(height: 100)
                   
                   Button("Start SeerBit checkout"){startCheckout = true}
                   Spacer()
               }
               .padding(20)
           }
       }
       .onReceive(NotificationCenter.default.publisher(for: Notification.Name(NotificationListenerConstants.closeCheckout.rawValue))) { data in
           // This block will be executed when the specified notification is received
           
           if let jsonData = data.userInfo?[NotificationListenerConstants.jsonData.rawValue] as? Data,
              let decodedData = try? JSONDecoder().decode(QueryTransactionDataModel?.self, from: jsonData) {
               transactionStatusData = decodedData
               print(decodedData, "data on sdk close")
               startCheckout = false
           }else{ startCheckout = false}
       }
   }
}


struct CustomInput: View {
   @State var textForegroundColor:Color =  Color.black
   @State var backgroundColor: Color = Color.black
   @Binding  var value: String
   @State  var placeHolder: String
   @State var rightText: String = ""
   @State var borderWidth: Int = 2
   
   @State var keyboardType: UIKeyboardType = .default
   
   
   var body: some View {
       HStack{
           TextField(placeHolder, text: $value)
               .foregroundStyle(textForegroundColor)
               .fontWeight(.regular)
               .font(.system(size: 12))
               .keyboardType(keyboardType)
           Spacer()
       }
       .padding(.horizontal, 11)
       .padding(.vertical, 12)
       .border(Color.gray, width: CGFloat(borderWidth))
       .clipShape(RoundedRectangle(cornerRadius: 4))
   }
} 

  • 上述代码将出现在您希望启动SeerBit结账的任何屏幕上。
  • transactionStatusData参数包含成功的交易响应数据,以便开发者在需要时使用这些数据。
  • The .onReceive监听结账关闭命令,并在存在transactionStatusData时返回。它必须按示例中的方法实现。

UIKit项目

import UIKit
import SwiftUI
import SeerBitCheckout

class ViewController: UIViewController {
   
   let transactionStatusData: QueryTransactionDataModel? = nil
   
   override func viewDidLoad() {
       super.viewDidLoad()
       
       let button = UIButton(frame: CGRect(x: 0, y: 0, width: 220, height: 50))
       view.addSubview(button)
       button.center = view.center
       button.setTitle("Load checkout", for: .normal)
       button.backgroundColor = .green
       button.addTarget(self, action: #selector(didTapButton), for: .touchUpInside)
       
       
       // Add observer for the custom notification
       NotificationCenter.default.addObserver(
           forName: Notification.Name(NotificationListenerConstants.closeCheckout.rawValue),
           object: nil,
           queue: nil
       ){ notification in
               
               if let jsonData = notification.userInfo?[NotificationListenerConstants.jsonData.rawValue] as? Data,
                  let decodedData = try? JSONDecoder().decode(QueryTransactionDataModel.self, from: jsonData) {
                   // Handle the decoded data
                   print(decodedData,"transaction response")
                   //close the checkout after
                   self.didCloseSdk()
               }else{
                   //you can perform any custom logic here, after which you close the sdk
                   self.didCloseSdk()
               }
           }
   }
   
   
   @objc func didTapButton() {
       let initSeerbitCheckout = InitSeerbitCheckout(
           amount: 200,
           fullName: "UIKit example",
           mobileNumber: "09098987676",
           publicKey: "business public key",
           email: "[email protected]"
       )
       
       let hostingController = UIHostingController(rootView: initSeerbitCheckout)
       present(hostingController, animated: true)
   }
   
   @objc func didCloseSdk() {
       // Dismiss the presented hosting controller
          dismiss(animated: true, completion: nil)
   }
   
   deinit {
       NotificationCenter.default.removeObserver(self)
   }
}


  • 上述代码代表了一个示例视图控制器,您可以从其中启动SeerBit结账。
  • 请确保设置通知中心观察者以监听来自sdk的关闭命令,并且在任何情况下都能访问成功交易数据。
  • 请确保调用deinit块以移除通知监听器,避免内存泄漏。
  • didTapButton 块中的代码可以从你想要开始结账的任何动作开始存在。

属性

属性 类型 必需 默认 描述
currency 字符串 可选 NGN 交易的货币,例如 NGN。
email 字符串 必需 要收费用户的电子邮件地址。
publicKey 字符串 必需 您的公钥或查看上面的步骤以获取您的公钥。
amount 字符串 必需 交易金额。
fullName 字符串 必需 被收费用户的全名。
phoneNumber 字符串 必需 用户电话号码。
pocketReference 字符串 可选 这将是向包含 pocket 的商家提供的一个参考。
vendorId 字符串 可选 这是在 pocket 上使用商家的 vendorId。
tokenize 布尔值 可选 False 标记化卡片。
country 字符串 可选 NG 交易国家,可以是可选的。
transactionPaymentReference 字符串 可选 为每笔交易设置一个唯一的交易参考。
productId 字符串 可选 这是可选的 productId。
productDescription 字符串 可选 这是可选的交易描述。

支持

如果您遇到任何问题,或者您有任何问题或建议,请在该仓库中创建一个问题,或将您的询问发送到 [email protected]