Swiftpack.co -  AcquiredSupport/Acquired-iOS-MacOS as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
AcquiredSupport/Acquired-iOS-MacOS
Process Apple Pay & Card Payments in-App.
.package(url: "https://github.com/AcquiredSupport/Acquired-iOS-MacOS.git", from: "1.0.0")

Acquired-iOS-MacOS

Description

The Acquired-iOS-MacOS SDK allows you to easily and securely integrate Apple Pay and Card Payments into your iOS or MacOS app.

Requirements

  • iOS 13+
  • MacOS 11+

Install the SDK

Use Swift Package Manager to install this SDK.

  1. Follow the steps in Adding Package Dependencies to Your App
  2. Set the repository URL to https://github.com/AcquiredSupport/Acquired-iOS-MacOS.

Once this is completed add "import ACQPaymentGateway".

Getting Started

Contact support@acquired.com to get started using the SDK. You will need the required configuration details as well as access to our backoffice.

Once you've got this, the SDK can be fully configured within the Acquired.com Hub allowing you to define what is supported and should be requested from the user on the payment sheet. For Apple Pay this includes:

  • Supported Card Networks (Visa, MasterCard, Amex)
  • Supported Card Types (Credit, Debit, Prepaid)
  • Required Billing Data (Address, Email, Phone)
  • Required Shipping Data (Address, Email, Phone)

Changes can be easily made to your configuration and payment page without the need to update or release your app.

Examples

Take a look at at the Acquired-iOS-ExampleApp for a SwiftUI implementation of the SDK.

How to use the SDK

Configuration

Create an instance of the PaymentGateway with a configuration:

private let paymentGateway: PaymentGateway = {
    let configuration = Configuration(
        companyId: "459",
        companyPass: "re3vKdCG",
        companyHash: "cXaFMLbH",
        companyMidId: "1687",
        baseUrl: "https://qaapi.acquired.com/",
        baseHppUrl: "https://qahpp.acquired.com",
        requestRetryAttempts: 3
    )
    return PaymentGateway(configuration: configuration)
}()

Payment Data

Get the available payment methods and required configuration data as configured in the Hub:

private func getData() {
      paymentGateway?.getPaymentData {
          switch $0 {
          case .success(let paymentData):
              let currency = paymentData.currency
              currencyCodeIso3 = currency.currencyCode
              currencyDigits = currency.currencyDigits
              paymentsTexts = paymentData.availablePaymentTypes.filter { $0.isActive }

          case .failure(let error):
              display(error: error)
          }
      }
  }

Start a Payment

Create a Transaction object and using a paymentMethod from the paymentData process a payment:

private func transaction() throws -> ACQTransaction {
    var merchantOrderId = Date().timeIntervalSince1970.description
    merchantOrderId = merchantOrderId.filter { $0 != "." }
    return ACQTransaction(
        transactionType: .authCapture,
        subscriptionType: .initial,
        merchantOrderId: merchantOrderId,
        merchantCustomerId: "5678",
        merchantCustom1: "custom1",
        merchantCustom2: "custom2",
        merchantCustom3: "custom3"
    )
}

private func cellTapped(_ paymentType: PaymentType) {
    guard let acqTransaction = try? transaction() else {
        return
    }
    pay(with: paymentType, for: acqTransaction)
}

func pay(with paymentType: PaymentType, for transaction: ACQTransaction) {
    paymentGateway?.pay(
        for: orderSummary,
        with: paymentType,
        transaction: transaction,
        window: window
    ) { result in
        switch result {
        case .success(let data):
            print("data: \(String(describing: data))")
            displaySuccess()

        case .failure(let error):
            display(error: error)
        }
        orderSummary.selectedShippingMethod = orderSummary.shippingMethods.first
    }
}

Error Handling

All known declines and errors are caught and handled by the SDK.

General Failures

Other than the ones detailed below, all other errors (for example, a parsing error from the Swift JsonDecoder) are just returned as standard Swift Errors.

PaymentError.userCancelled PaymentError.MissingInformation(String)

Specific Failures

When you get the PaymentData, we return an array of grouped response_code values returned in a PaymentAuthorizationError:

PaymentAuthorizationError.Declined
PaymentAuthorizationError.Error
PaymentAuthorizationError.Blocked
PaymentAuthorizationError.Pending
PaymentAuthorizationError.Quarantined
PaymentAuthorizationError.TdsFailure
PaymentAuthorizationError.Unknown
PaymentAuthorizationError.InvalidCode

In there is a validation issue when loading the payment page, we will return a HostedPaymentError which has a code and localizedDecription.

Security Error

The SDK is secured using Certificate Pinning through TrustKit. In the event that this fails the SDK will return a CertificatePinningError.

GitHub

link
Stars: 1
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

1.0.0
2 weeks ago

Release 1.0.0

ACQPaymentSDK features:

ApplePay payments Card payments via a hosted payment page provided by the SDK Certificate pinning of the Acquired domain using TrustKit

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics