ios上显示带有地址字段的STPAddCardViewController

时间:2017-03-10 09:26:05

标签: ios swift stripe-payments

我尝试使用条带库中的STPAddCardViewController来显示添加卡片的视图,并将其配置为需要地址。 这就是我所拥有的,它不起作用并抛出异常:

@IBAction func addCardAction(sender: AnyObject)
{

    let paymentConfig = STPPaymentConfiguration.init();
    paymentConfig.requiredBillingAddressFields = STPBillingAddressFields.Full;

    let theme = STPTheme.defaultTheme();

    let addCardViewController = STPAddCardViewController.init(configuration: paymentConfig, theme: theme);
    addCardViewController.delegate = self;

    let navigationController = UINavigationController(rootViewController: addCardViewController);
    self.presentViewController(navigationController, animated: true, completion: nil);
}

如果我只是在没有配置的情况下进行初始化,我会看到卡片和电子邮件字段(没有地址)的视图很好,如下所示:

@IBAction func addCardAction(sender: AnyObject)
{

    let addCardViewController = STPAddCardViewController()
    addCardViewController.delegate = self

    let navigationController = UINavigationController(rootViewController: addCardViewController)
    self.presentViewController(navigationController, animated: true, completion: nil)        
}

我看到例外:

  

由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' *** - [__ NSCFConstantString stringByAppendingString:]:nil参数'

抛出这一行:

let addCardViewController = STPAddCardViewController.init(configuration: paymentConfig, theme: theme);

1 个答案:

答案 0 :(得分:0)

尝试将您的publishableKey添加到paymentConfig,为我修复

    paymentConfig.publishableKey = "pk_test_xxxxxxxx"