GlobalPayments-iOS-SDK 3.0.2

GlobalPayments-iOS-SDK 3.0.2

GP-API SDK Dev TeamHPS dev Portal Team 维护。



  • Global Payments
Global Payments logo

GlobalPayments iOS库

您可以在https://developer.globalpay.com上找到有关如何使用此库的信息并为免费Global Payments沙盒账户注册。

需求

  • iOS 9.0+
  • Xcode 11+
  • Swift 5.0+

安装

CocoaPods

  1. 要将Global Payments iOS库集成到您的Xcode项目中使用CocoaPods,请在您项目的Podfile中指定它
pod 'GlobalPayments-iOS-SDK', '~> 1.0'
  1. 然后,运行以下命令
$ pod install

手册

如果您不想使用依赖管理器,可以手动将Global Payments iOS库集成到项目中。

文档和示例

您可以在Global Payments开发者中心找到最新SDK的文档以及代码示例和测试卡数据:Global Payments开发者中心。

此外,您还可以在我们的示例代码仓库中找到工作示例。

提示:包含的测试套件可以是使用SDK的代码样例的极佳来源!

处理支付示例

/// Prepare required configuration
let config = GpApiConfig (
    appId: "Your application ID",
    appKey: "Your application key"
)

/// Add config to container
try ServicesContainer.configureService(config: config)

/// Prepare card
let card = CreditCardData()
card.number = "4111111111111111"
card.expMonth = 12
card.expYear = 2025
card.cvn = "123"
card.cardHolderName = "Joe Smith"

// Execute operation
card.charge(amount: 19.99)
    .withCurrency("USD")
    .execute { transaction, error in
        // Handle transaction response or error
}

测试卡数据

姓名 卡号 有效期月份 有效期年份 CVN
Visa 4263970000005262 12 2025 123
万事达卡 2223000010005780 12 2019 900
万事达卡 5425230000004415 12 2025 123
发现卡 6011000000000087 12 2025 123
美国运通卡 374101000000608 12 2025 1234
JCB 3566000000000000 12 2025 123
大莱卡 36256000000725 12 2025 123

测试异常

在您的集成过程中,您可能想要测试特定的发卡行响应,例如“卡片被拒绝”。由于我们的沙箱环境实际上并未接触发卡行的授权请求,因此存在特定的交易金额和/或卡号将会触发网关和发卡行的响应。请联系您的支持代表获取用于模拟交易AVS/CVV结果、拒绝、错误和其他响应值的完整列表。示例错误处理代码

card.charge(amount: 19.99)
    .withCurrency("USD")
    .withAddress(address)
    .execute { transaction, error in
        if let error = error as? BuilderException {
            // handle builder errors
        } else if let error = error as? ConfigurationException {
            // handle errors related to your services configuration
        } else if let error = error as? GatewayException {
            // handle gateway errors/exceptions
        } else if let error = error as? UnsupportedTransactionException {
            // handle errors when the configured gateway doesn't support desired transaction
        } else if let error = error as? ApiException {
            // handle all other errors
        }
    }

贡献

我们所有的代码都是开源的,我们鼓励同行开发者贡献力量并改进它!

  1. 复制项目(Fork it)
  2. 创建您的功能分支(git checkout -b my-new-feature
  3. 确保SDK测试通过
  4. 提交您的更改(git commit -am '添加一些功能'
  5. 推送到分支(git push origin my-new-feature
  6. 创建新的Pull Request

授权

本项目受GNU通用公共许可证v2.0的许可。请参阅位于项目根目录的LICENSE.md以获取更多信息。