Braintree iOS Drop-in SDK - 一站式支付解决方案

Braintree iOS Drop-in SDK

Braintree iOS Drop-in SDK 是一个功能强大的支付集成解决方案,为iOS应用提供了一套完整的支付UI组件。它支持多种支付方式,包括信用卡、PayPal、Venmo和Apple Pay,让开发者能够快速集成安全可靠的支付功能。

功能特性

  • 多支付方式支持:集成信用卡、PayPal、Venmo和Apple Pay等多种支付方式
  • UI自定义 :通过BTDropInUICustomization全面自定义UI样式和颜色方案
  • 安全支付处理:支持3D Secure验证和安全的支付信息处理
  • 支付管理:提供支付方式的保存、管理和选择功能
  • 国际化支持:包含多语言本地化和RTL布局支持
  • 无障碍访问:默认支持动态字体大小和无障碍功能
  • 现代技术栈:要求Xcode 15.0+和Swift 5.9+,支持iOS 12.0+

安装指南

Swift Package Manager

swift 复制代码
dependencies: [
    .package(url: "https://github.com/braintree/braintree-ios-drop-in", from: "9.14.0")
]

CocoaPods

ruby 复制代码
pod 'BraintreeDropIn'

系统要求

  • iOS 12.0+
  • Xcode 15.0+
  • Swift 5.9+

使用说明

基本集成

swift 复制代码
import BraintreeDropIn

// 初始化Drop-in控制器
let dropInRequest = BTDropInRequest()
dropInRequest.cardholderNameSetting = .required
dropInRequest.vaultCard = true

let dropIn = BTDropInController(authorization: "your_client_token", 
                               request: dropInRequest) 
{ (controller, result, error) in
    if let error = error {
        print("Error: \(error.localizedDescription)")
    } else if let result = result {
        // 处理支付结果
        print("Payment method type: \(result.paymentMethodType)")
        print("Payment description: \(result.paymentDescription)")
    }
    controller.dismiss(animated: true)
}

// 呈现Drop-in界面
present(dropIn!, animated: true)

UI自定义示例

swift 复制代码
let uiCustomization = BTDropInUICustomization(colorScheme: .light)
uiCustomization.fontFamily = "Helvetica"
uiCustomization.boldFontFamily = "Helvetica-Bold"
uiCustomization.tintColor = .systemBlue

let dropInRequest = BTDropInRequest()
dropInRequest.uiCustomization = uiCustomization

获取最近支付方式

swift 复制代码
BTDropInResult.mostRecentPaymentMethod(forClientToken: clientToken) { result, error in
    if let result = result {
        // 显示最近使用的支付方式
        let paymentIcon = result.paymentIcon
        let description = result.paymentDescription
    }
}

核心代码

支付表单控制器

swift 复制代码
// BTCardFormViewController.h
@interface BTCardFormViewController : BTDropInBaseViewController <UITextFieldDelegate>

@property (nonatomic, strong, readonly) BTUIKCardNumberFormField *cardNumberField;
@property (nonatomic, strong, readonly) BTUIKCardholderNameFormField *cardholderNameField;
@property (nonatomic, strong, readonly) BTUIKExpiryFormField *expirationDateField;
@property (nonatomic, strong, readonly) BTUIKSecurityCodeFormField *securityCodeField;

// 如果表单有效,返回BTCardRequest
@property (nonatomic, strong, nullable, readonly) BTCardRequest *cardRequest;

@end

UI定制配置

swift 复制代码
// BTDropInUICustomization.m
- (instancetype)initWithColorScheme:(BTDropInColorScheme)colorScheme {
    if (self = [super init]) {
        _useBlurs = YES;
        _postalCodeFormFieldKeyboardType = UIKeyboardTypeDefault;

        switch(colorScheme) {
            case BTDropInColorSchemeLight:
                _barBackgroundColor = UIColor.whiteColor;
                _formBackgroundColor = [UIColor btuik_colorFromHex:@"EFEFF4" alpha:1.0];
                _primaryTextColor = UIColor.blackColor;
                _secondaryTextColor = [UIColor btuik_colorFromHex:@"3C3C43" alpha:1.0];
                break;
            case BTDropInColorSchemeDark:
                _barBackgroundColor = [UIColor btuik_colorFromHex:@"222222" alpha:1.0];
                _formBackgroundColor = [UIColor btuik_colorFromHex:@"222222" alpha:1.0];
                _primaryTextColor = UIColor.whiteColor;
                _secondaryTextColor = [UIColor btuik_colorFromHex:@"EBEBF5" alpha:1.0];
                break;
            default: // dynamic
                if (@available(iOS 13, *)) {
                    _barBackgroundColor = UIColor.systemBackgroundColor;
                    _formBackgroundColor = UIColor.systemGroupedBackgroundColor;
                    _primaryTextColor = UIColor.labelColor;
                    _secondaryTextColor = UIColor.secondaryLabelColor;
                }
        }
    }
    return self;
}

支付方式处理

swift 复制代码
// BTPaymentMethodNonce+DropIn.m
- (NSString *)paymentDescription {
    if ([self isKindOfClass:[BTCardNonce class]]) {
        return ((BTCardNonce *)self).lastFour;
    } else if ([self isKindOfClass:[BTPayPalAccountNonce class]]) {
        return ((BTPayPalAccountNonce *)self).email;
    } else if ([self isKindOfClass:[BTVenmoAccountNonce class]]) {
        return ((BTVenmoAccountNonce *)self).username;
    } else if ([self isKindOfClass:[BTApplePayCardNonce class]]) {
        return @"Apple Pay";
    } else {
        return @"";
    }
}

基础视图控制器

swift 复制代码
// BTDropInBaseViewController.m
- (instancetype)initWithAPIClient:(BTAPIClient *)apiClient request:(BTDropInRequest *)request {
    if (self = [super init]) {
        self.apiClient = apiClient;
        _dropInRequest = request;
    }
    return self;
}

- (void)loadConfiguration {
    [self.apiClient fetchOrReturnRemoteConfiguration:^(BTConfiguration *configuration, NSError *error) {
        self.configuration = configuration;
        [self configurationLoaded:configuration error:error];
    }];
}
相关推荐
科技小郑2 小时前
吱吱企业即时通讯以安全为基,重塑安全办公新体验
大数据·网络·人工智能·安全·信息与通信·吱吱企业通讯
就叫飞六吧2 小时前
生产环境禁用AI框架工具回调:安全风险与最佳实践
人工智能·安全
r0ad2 小时前
如何让大模型秒懂你的意图?提示工程三大绝招揭秘
aigc
胡乱编胡乱赢2 小时前
关于在pycharm终端连接服务器
人工智能·深度学习·pycharm·终端连接服务器
聚客AI2 小时前
⚠️Embedding选型指南:五步搞定数据规模、延迟与精度平衡!
人工智能·llm·掘金·日新计划
h_k100863 小时前
Manus AI与多语言手写识别
人工智能
就是一顿骚操作3 小时前
mcp解读——概述及整体架构
人工智能·大模型
程序猿阿伟3 小时前
《云原生边缘与AI训练场景:2类高频隐蔽Bug的深度排查与架构修复》
人工智能·云原生·bug
l1t3 小时前
利用美团龙猫添加xlsx的sheet.xml读取sharedStrings.xml中共享字符串输出到csv功能
xml·c语言·数据结构·人工智能·算法·解析器