XHPayKit

Introduction

Welcome to the documentation for XHPayKit – a comprehensive payment integration library for iOS apps. This documentation will provide you with detailed information on how to integrate payment functionality into your iOS app using XHPayKit.

Requirements

In order to use XHPayKit, you need the following:

  • iOS 11.0 or above
  • Xcode 10.0 or above
  • Swift 5.0 or above

Installation

Follow the steps below to install XHPayKit in your project:

  1. Open your project in Xcode.
  2. Add the XHPayKit dependency to your Podfile:

“`ruby
pod ‘XHPayKit’
“`

  1. Run the command pod install in the terminal to install the dependency.
  2. Open your project’s workspace file (with the .xcworkspace extension) in Xcode.
  3. Import the XHPayKit module in the Swift file where you want to use it:

“`swift
import XHPayKit
“`

Getting Started

To get started with XHPayKit, follow the steps below:

  1. Create an instance of the XHPayManager class:

“`swift
let payManager = XHPayManager()
“`

  1. Configure the payment options:

“`swift
payManager.configure(paymentOptions: [.applePay, .creditCard])
“`

  1. Implement the necessary delegate methods of XHPayManagerDelegate to handle payment callbacks:

“`swift
class PaymentViewController: UIViewController, XHPayManagerDelegate {
//…

func paymentDidSucceed() {
// Handle successful payment
}

func paymentDidFail(error: Error) {
// Handle payment failure
}

//…
}
“`

  1. Present the payment view controller and initiate payment:

“`swift
let paymentVC = PaymentViewController()
payManager.presentPayment(from: self)
“`

Payment Options

XHPayKit supports the following payment options:

  • Apple Pay
  • Credit Card
  • PayPal
  • Google Pay

Apple Pay Integration

To integrate Apple Pay with XHPayKit, follow the steps below:

  1. Configure Apple Pay Merchant ID and other settings in your Xcode project:

“`swift
XHPayConfig.shared.configureApplePay(merchantID: “your_merchant_id”, countryCode: “your_country_code”, currencyCode: “your_currency_code”)
“`

  1. Add the necessary entitlements for Apple Pay to your project:

“`xml
com.apple.developer.payment-pass-provisioning

your_merchant_id

com.apple.developer.in-app-payments

your_merchant_id

“`

  1. Implement the necessary delegate method of XHPayManagerDelegate to handle Apple Pay completion:

“`swift
class PaymentViewController: UIViewController, XHPayManagerDelegate {
//…

func applePayAuthorizationDidFinish(paymentToken: String?, error: Error?) {
if let token = paymentToken {
// Handle successful Apple Pay payment
} else if let error = error {
// Handle Apple Pay payment failure
}
}

//…
}
“`

Credit Card Integration

To integrate credit card payments with XHPayKit, follow the steps below:

  1. Implement the necessary delegate method of XHPayManagerDelegate to handle credit card payment completion:

“`swift
class PaymentViewController: UIViewController, XHPayManagerDelegate {
//…

func creditCardPaymentDidFinish(token: String?, error: Error?) {
if let token = token {
// Handle successful credit card payment
} else if let error = error {
// Handle credit card payment failure
}
}

//…
}
“`

PayPal Integration

To integrate PayPal payments with XHPayKit, follow the steps below:

  1. Add the necessary configurations for PayPal in the AppDelegate.swift file:

“`swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//…
XHPayConfig.shared.configurePayPal(clientID: “your_paypal_client_id”, environment: .sandbox) // or .production
//…
return true
}
“`

  1. Implement the necessary delegate method of XHPayManagerDelegate to handle PayPal payment completion:

“`swift
class PaymentViewController: UIViewController, XHPayManagerDelegate {
//…

func payPalPaymentDidFinish(paymentToken: String?, error: Error?) {
if let token = paymentToken {
// Handle successful PayPal payment
} else if let error = error {
// Handle PayPal payment failure
}
}

//…
}
“`

Google Pay Integration

To integrate Google Pay with XHPayKit, follow the steps below:

  1. Configure the necessary settings in the AppDelegate.swift file:

“`swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
//…
XHPayConfig.shared.configureGooglePay(merchantID: “your_merchant_id”) // Set your Google Pay merchant ID
//…
return true
}
“`

  1. Implement the necessary delegate method of XHPayManagerDelegate to handle Google Pay completion:

“`swift
class PaymentViewController: UIViewController, XHPayManagerDelegate {
//…

func googlePayPaymentDidFinish(paymentToken: String?, error: Error?) {
if let token = paymentToken {
// Handle successful Google Pay payment
} else if let error = error {
// Handle Google Pay payment failure
}
}

//…
}
“`

Conclusion

Congratulations! You now have the knowledge to integrate payment functionality into your iOS app using XHPayKit. Feel free to explore the various payment options and customize the payment process based on your requirements. If you have any questions or need further assistance, please refer to the API documentation or reach out to our support team.