stripe支付的核心代码

import UIKit
import Stripeclass CheckoutViewController: UIViewController, STPPaymentContextDelegate {// 1) To get started with this demo, first head to https://dashboard.stripe.com/account/apikeys// and copy your "Test Publishable Key" (it looks like pk_test_abcdef) into the line below.let stripePublishableKey = "pk_test_8LwPyj7Srlke48c6MIohzaGW"// 2) Next, optionally, to have this demo save your user's payment details, head to// https://github.com/stripe/example-ios-backend , click "Deploy to Heroku", and follow// the instructions (don't worry, it's free). Replace nil on the line below with yourlet backendBaseURL: String? = nil //"http://:8083/pay.json?"// 3) Optionally, to enable Apple Pay, follow the instructions at https://stripe.com/docs/mobile/apple-pay// to create an Apple Merchant ID. Replace nil on the line below with it (it looks like merchant.com.yourappname).let appleMerchantID: String? = nil// These values will be shown to the user when they purchase with Apple Pay.let companyName = "Emoji Apparel"let paymentCurrency = "usd"let paymentContext: STPPaymentContextlet theme: STPThemelet paymentRow: CheckoutRowViewlet totalRow: CheckoutRowViewlet buyButton: BuyButtonlet rowHeight: CGFloat = 44let productImage = UILabel()let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)var product = ""var paymentInProgress: Bool = false {didSet {UIView.animate(withDuration: 0.3, delay: 0, options: .curveEaseIn, animations: {if self.paymentInProgress {self.activityIndicator.startAnimating()self.activityIndicator.alpha = 1self.buyButton.alpha = 0}else {self.activityIndicator.stopAnimating()self.activityIndicator.alpha = 0self.buyButton.alpha = 1}}, completion: nil)}}init(product: String, price: Int, settings: Settings) {self.product = productself.productImage.text = productself.theme = settings.themeself.paymentRow = CheckoutRowView(title: "Payment", detail: "Select Payment",theme: settings.theme)self.totalRow = CheckoutRowView(title: "Total", detail: "", tappable: false,theme: settings.theme)self.buyButton = BuyButton(enabled: true, theme: settings.theme)MyAPIClient.sharedClient.baseURLString = self.backendBaseURL// This code is included here for the sake of readability, but in your application you should set up your configuration and theme earlier, preferably in your App Delegate.let config = STPPaymentConfiguration.shared()config.publishableKey = self.stripePublishableKeyconfig.appleMerchantIdentifier = self.appleMerchantIDconfig.companyName = self.companyNameconfig.requiredBillingAddressFields = settings.requiredBillingAddressFieldsconfig.additionalPaymentMethods = settings.additionalPaymentMethodsconfig.smsAutofillDisabled = !settings.smsAutofillEnabledlet paymentContext = STPPaymentContext(apiAdapter: MyAPIClient.sharedClient,configuration: config,theme: settings.theme)let userInformation = STPUserInformation()paymentContext.prefilledInformation = userInformationpaymentContext.paymentAmount = pricepaymentContext.paymentCurrency = self.paymentCurrencyself.paymentContext = paymentContextsuper.init(nibName: nil, bundle: nil)self.paymentContext.delegate = selfpaymentContext.hostViewController = self}required init?(coder aDecoder: NSCoder) {fatalError("init(coder:) has not been implemented")}override func viewDidLoad() {super.viewDidLoad()self.view.backgroundColor = self.theme.primaryBackgroundColorvar red: CGFloat = 0self.theme.primaryBackgroundColor.getRed(&red, green: nil, blue: nil, alpha: nil)self.activityIndicator.activityIndicatorViewStyle = red < 0.5 ? .white : .grayself.navigationItem.title = "Emoji Apparel"self.productImage.font = UIFont.systemFont(ofSize: 70)self.view.addSubview(self.totalRow)self.view.addSubview(self.paymentRow)self.view.addSubview(self.productImage)self.view.addSubview(self.buyButton)self.view.addSubview(self.activityIndicator)self.activityIndicator.alpha = 0self.buyButton.addTarget(self, action: #selector(didTapBuy), for: .touchUpInside)self.totalRow.detail = "$\(self.paymentContext.paymentAmount/100).00"self.paymentRow.onTap = { [weak self] _ inself?.paymentContext.pushPaymentMethodsViewController()}}override func viewDidLayoutSubviews() {super.viewDidLayoutSubviews()let width = self.view.bounds.widthself.productImage.sizeToFit()self.productImage.center = CGPoint(x: width/2.0,y: self.productImage.bounds.height/2.0 + rowHeight)self.paymentRow.frame = CGRect(x: 0, y: self.productImage.frame.maxY + rowHeight,width: width, height: rowHeight)self.totalRow.frame = CGRect(x: 0, y: self.paymentRow.frame.maxY,width: width, height: rowHeight)self.buyButton.frame = CGRect(x: 0, y: 0, width: 88, height: 44)self.buyButton.center = CGPoint(x: width/2.0, y: self.totalRow.frame.maxY + rowHeight*1.5)self.activityIndicator.center = self.buyButton.center}func didTapBuy() {self.paymentInProgress = trueself.paymentContext.requestPayment()}func paymentContext(_ paymentContext: STPPaymentContext, didCreatePaymentResult paymentResult: STPPaymentResult, completion: @escaping STPErrorBlock) {MyAPIClient.sharedClient.completeCharge(paymentResult, amount: self.paymentContext.paymentAmount,completion: completion)}func paymentContext(_ paymentContext: STPPaymentContext, didFinishWith status: STPPaymentStatus, error: Error?) {self.paymentInProgress = falselet title: Stringlet message: Stringswitch status {case .error:title = "Error"message = error?.localizedDescription ?? ""case .success:title = "Success"message = "You bought a \(self.product)!"case .userCancellation:return}let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)let action = UIAlertAction(title: "OK", style: .default, handler: nil)alertController.addAction(action)self.present(alertController, animated: true, completion: nil)}// MARK: STPPaymentContextDelegatefunc paymentContextDidChange(_ paymentContext: STPPaymentContext) {self.paymentRow.loading = paymentContext.loadingif let paymentMethod = paymentContext.selectedPaymentMethod {self.paymentRow.detail = paymentMethod.label}else {self.paymentRow.detail = "Select Payment"}}func paymentContext(_ paymentContext: STPPaymentContext, didFailToLoadWithError error: Error) {let alertController = UIAlertController(title: "Error",message: error.localizedDescription,preferredStyle: .alert)let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: { action in// Need to assign to _ because optional binding loses @discardableResult value// https://bugs.swift.org/browse/SR-1681_ = self.navigationController?.popViewController(animated: true)})let retry = UIAlertAction(title: "Retry", style: .default, handler: { action inself.paymentContext.retryLoading()})alertController.addAction(cancel)alertController.addAction(retry)self.present(alertController, animated: true, completion: nil)}}

其实只是复制了下官方demo的代码。。。
官网地址:https://stripe.com/docs/mobile/ios
测试数据:https://stripe.com/docs/testing



对于前端来说,集成stripe进行支付的大体流程如下:
pod install 。。。
配置stripe:
1)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if (StripePublishableKey) {
[Stripe setDefaultPublishableKey:StripePublishableKey];
}
return YES;
}

2)
获取stripe的支付token(iOS端基本就是几个代理方法就OK)
3)
将所选商品总价、tokenId 等后台所需数据配置好post给自己的服务端(真正的支付操作),让自己的服务端去请求 stripeServer 端
4)
自己的服务端会根据stripeserver端的请求结果返回支付状态,前端根据该返回值进行相应处理即可

关键代码在 这篇文章,如token的创建,chage的生成等

stripe 海外支付相关推荐

  1. Stripe 银行卡支付功能初步指南(Java)

    Stripe 国外银行卡支付功能指南(Java) 简介 编写这篇文章的目的就是~~没有什么目的.网上关于stripe银行卡支付代码很多,有写得很好的,但是太多太杂了,不系统.所以我就结合项目中实际应用 ...

  2. stripe国际支付(对接支付宝、微信)

    前言:stripe国际支付现在网上资料很少,且不支持中国,所以如果要用需要去支持的国家注册商户,官网的java demo是用的spark框架,我这里用的spring,验签需要手动验签,且不能用官网的方 ...

  3. PayPal/Stripe/Square轮询收单系统 stripe paymentlink支付模式

    stripe paymentlink支付模式, 他的模式是最新的,所有需要下载最新的sdk插件,通过composer安装后就可以按照以下步骤就使用了 function Stripepaymentlin ...

  4. 金融科技大数据产品推荐: 换汇API/海外支付API——让跨境支付更简单

    官网 | www.datayuan.cn 微信公众号ID | datayuancn 本产品为数据猿推出的"金融科技价值-数据驱动金融商业裂变"大型主题策划活动第一部分的文章/案例/ ...

  5. 如何快速对接Stripe国际支付系统

    Stripe国际支付介绍 Stripe是由20多岁的两兄弟Patrick Collison和John Collison创办的Stripe为公司提供网上支付的解决方案.Stripe向服务的公司收取每笔交 ...

  6. 银联国际开启欧洲业务,海外支付市场激战不断

    近日,银联国际与葡萄牙最大的私有银行葡萄牙商业银行(Millennium bcp)在里斯本签署发卡协议.葡萄牙将发行当地首张银联卡,全球发行银联卡的国家和地区增至50个.此次合作也是继欧洲8个国家的中 ...

  7. 海外支付:遍布全球的Paypal

    海外支付:遍布全球的Paypal 吴剑 2015-11-26 原创文章,转载必需注明出处:http://www.cnblogs.com/wu-jian 吴剑 http://www.cnblogs.co ...

  8. Stripe 银行卡支付(Java)

    Stripe 银行卡支付(Java) 一:概述 参考博客:https://blog.csdn.net/Sunshine_Moon/article/details/113867159?utm_mediu ...

  9. php集成Stripe支付,海外支付stripe对接支付

    发表于 2017-03-15 09:35:49 by 月小升 strip https:// data-key="pk_test_wIAv7SdDJV2B6zPPUdnXnJCd" ...

  10. Springboot 整合 Stripe 国际支付进行收款操作,Stripe 国际支付的支付流程

    之前我们写了海外的印度 Razorpay 支付,Razorpay 的付款流程跟国内基本是一样的,首先拿着金额等信息生成订单号,再根据订单号进行支付,本次简单的了解下 Stripe 支付流程,进行一下支 ...

最新文章

  1. 设置自动关门时长_小米苹果全适配,绿米D100全自动指纹锁新鲜上手
  2. 二分类任务:确定一个人是否年收入超过5万美元
  3. YAML简介和简单说明
  4. python中扑克牌类设计_Python类的基础设计、使用
  5. Struts1.2配置详解
  6. 菜鸟做HTML5小游戏 - 刮刮乐
  7. c语言自学门槛,初学C语言的人最常问的几个问题
  8. Mysql简介和Mysql优化查询的方法
  9. 玩转Java注解:元注解、内置注解、自定义注解的原理和实现
  10. 纽微特纪事:改个字串,竟然成了“二期工作”,还拖了几个月
  11. jquery导入数据_python大数据实践之三:对分析结果可视化呈现
  12. 如何高效率安排你的时间?Mac精品日程管理软件推荐
  13. YUV和RGB调节色彩公式
  14. 蓝桥杯day7——DFSBFS
  15. 中望3d快捷键命令大全_CAD、3D快捷命令
  16. 笹山希 java,C#版数据结构与算法高级教程(深入探讨)--附各种算法实例-升级版
  17. Apollo6.0 + lgSVL 联合仿真平台搭建
  18. java lint_提高你的代码稳定性与可读性-lint工具
  19. PPT/Word中英文单词换行问题 (取消了西文在单词中间换行的选项,但英文部分依然不连续) 的解决方法
  20. java 图形界面

热门文章

  1. 高手攻关考试心得:RHCE实战详细经验
  2. RTKLIB专题学习(四)---单点定位实现初识(一)
  3. 机器学习(四):关于模型复杂度与模型性能的关系
  4. 统一身份管理项目最佳实践
  5. 留美学子安全手册,这个可以有
  6. S5PV210 DDR2初始化 28个步骤总结
  7. mysql商品库存字段_mysql商品库存扣减问题总结
  8. 如何用python自动改试卷_利用python爬取软考试题之ip自动代理
  9. RabbitMQ实现即时通讯
  10. 关于Tween的几个注意事项