- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要按照以下说明发出 http post 请求:
curl https://api.stripe.com/v1/tokens \
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
-d "bank_account[country]=US" \
-d "bank_account[routing_number]=110000000" \
-d "bank_account[account_number]=000123456789"
我不知道如何从 curl 转到 NSUrlrequest,尤其是 -u(用户?)部分。 stripe SDK 已将其从他们的 SDK 中删除,并且在他们的网站上没有示例。
谢谢
最佳答案
编辑:我专门为获取 bank_account 的 token 创建了另一个答案。这个答案通常是关于如何使用创建收件人的示例使用解析的后端进行调用。
stipe 文档在这里有点偏离,创建 bank_account token 的调用实际上是直接从应用程序使用可发布 key 进行的。确保不要在 iOS 应用程序本身中使用您的 key 。只能通过以下方式使用您的公钥:
[Stripe setDefaultPublishableKey:@"pk_test_your_test_key_here"];
您需要使用网络后端来实现 Stripe 支付系统的完整功能。他们包含的 ios sdk 只能让您从信用卡中获取 token 。 Web 后端在那里你可以实现 key 。我使用 parse.com 作为我的 stripe 后端,但许多实现了他们自己的。
下面是一个简单的 httpRequest 云代码,可以执行大多数 stripe 任务。为它提供方法、前缀、后缀、后缀,然后是请求的参数。我并不是说这是实现 stripe 的 httpRequests 的最佳方式,但它涵盖了您开始使用它的基础。下面的代码已经过测试,并且可以正常工作,我在我的 strip 测试沙箱中创建了一个 john doe 收件人。
解析云代码:
var Stripe = require('stripe');
var STRIPE_SECRET_KEY = 'sk_test_yoursecretkeyhere';
var STRIPE_API_BASE_URL = 'api.stripe.com/v1/'
Stripe.initialize(STRIPE_SECRET_KEY);
Parse.Cloud.define("stripeHTTPRequest", function(request, response)
{
//check for suffix, and postfix
var suffix = "";
if (!isEmpty(request.params["suffix"])) {
suffix = '/'+request.params['suffix'];
}
var postfix = "";
if (!isEmpty(request.params["postfix"])) {
postfix = '/'+request.params['postfix'];
}
Parse.Cloud.httpRequest({
method: request.params["method"],
url: 'https://' + STRIPE_SECRET_KEY + ':@' + STRIPE_API_BASE_URL + request.params["prefix"] + suffix + postfix,
params:request.params["parameters"],
success: function(httpResponse) {
response.success(httpResponse.text);
},
error: function(httpResponse) {
response.error('Request failed with response code' + httpResponse.status);
}
});
});
function isEmpty(obj) {
// null and undefined are "empty"
if (obj == null) return true;
// Assume if it has a length property with a non-zero value
// that that property is correct.
if (obj.length > 0) return false;
if (obj.length === 0) return true;
// Otherwise, does it have any properties of its own?
// Note that this doesn't handle
// toString and valueOf enumeration bugs in IE < 9
for (var key in obj) {
if (hasOwnProperty.call(obj, key)) return false;
}
return true;
}
因此,当涉及到创建收件人时,您可以为其提供“POST”方法和“收件人”前缀,并将后缀和后缀留空。这将生成这样的 url:
https://sk_test_yoursecretkeyhere:@api.stripe.com/v1/recipients
除了方法和 pre/suf/postfix 之外,您还需要为其提供参数。您可以通过发送键控对象字典来做到这一点。使用 Stripe 的文档,让我们创建一个名为 john doe 的收件人:
-d "name=John Doe" \
-d type=individual \
-d tax_id=000000000 \
-d "email=test@example.com" \
-d "description=Recipient for John Doe"
这里是使用李四示例的云代码的 iOS 调用。我已经实现了一个通用方法,你传递方法、pre/suf/postfix 和参数。然后,我创建了许多其他方法来处理特定的 strip 调用,例如创建收件人。
ViewController.m
-(void)createJohnDoe
{
NSDictionary *parameters = @{@"name":@"John Doe",
@"type":@"individual",
@"tax_id":@"000000000",
@"email":@"test@example.com",
@"description":@"Recipient for John Doe"
};
[ELStripe executeStripeCloudCodeWithMethod:@"POST" prefix:@"recipients" suffix:nil postfix:nil parameters:parameters completionHandler:^(id jsonObject, NSError *error) {
//jsonObject will be a dictionary that would need be parsed into your recipient object
NSLog(@"jsonObject:%@",jsonObject);
}];
}
ELStripe.m
//Completion Handler Definition.
typedef void (^ELStripeCompletionBlock)(id jsonObject, NSError *error);
+(void)executeStripeCloudCodeWithMethod:(NSString *)method prefix:(NSString *)prefix suffix:(NSString *)suffix postfix:(NSString *)postfix parameters:(NSDictionary *)parameters completionHandler:(ELStripeCompletionBlock)handler
{
[PFCloud callFunctionInBackground:@"stripeHTTPRequest" withParameters:@{@"method":method, @"prefix":prefix?prefix:@"", @"suffix":suffix?suffix:@"", @"postfix":postfix?postfix:@"", @"parameters":parameters} block:^(id object, NSError *error) {
id jsonObject;
if (!error) {
NSError *jsonError = nil;
jsonObject = [NSJSONSerialization JSONObjectWithData:[object dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:&jsonError];
}
handler(jsonObject,error);
}];
}
关于curl - 来自 strip curl 的 NSUrlRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24875772/
我正在使用 NSURLRequest 发送帖子。 NSURL *url = [NSURL URLWithString:someUrlString]; NSMutableURLRequest *theR
当我从后台打开应用程序时,我需要访问服务器来获取一些数据。当我这样做时,我收到如下警报: "Request timed out" (nserror's localised description) 我
我遇到了一个奇怪的问题。我在我的设备上运行 iOS 4.3.2。在 Xcode 4 中编译,但我没有使用 iOS 5 beta SDK。 我的应用程序从服务器获取一个 plist 文件,该 plist
作为一名 iOS 开发新手,我正在尝试了解一些与 iOS 中回调机制相关的概念。 我的模型通过 NSURLRequest 向后端休息服务发出 HTTP 请求。该模型有几个与服务中的方法相对应的方法。
关闭。这个问题需要更多focused 。目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 8 年前。 Improve this qu
我正在使用 php 和 mysql 数据库开发 iOS 网络应用程序,我的问题是 nsurl 请求获取 php 文件的值没有响应并且不工作但是,我正在命令提示符 url 中打印并复制 url 粘贴并转
我正在尝试设置一个 NSURLRequest 来下载一个简单的 index.html 及其 externa style.css 表,但我不太确定该怎么做。我只是将请求的 URL 格式化为我想要的文件.
这个问题在这里已经有了答案: Managing multiple asynchronous NSURLConnection connections (13 个答案) 关闭 9 年前。
我有一个用 swift 编写的应用程序,它使用 PHP 与我的服务器通信。在我的整个测试过程中,该应用程序运行完美,直到我开始同时在多个设备上进行测试。当我尝试同时加载两个设备时,它会偶尔(不是 10
我创建了一个 NSURLRequest 和一个 NSURLConnection 对象,并在 NSMutableData 实例中收集数据。然后,我根据下载的数据创建一个 NSString 并获取如下所示
通常 http 用户代理是这样的: Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18
我正在使用 NSURLRequest 和 CachePolicy 在 NSData 中下载一个 plist。当我更改我的 plist 的内容时,我的应用程序忽略了这一点并仍然显示缓存的内容。缓存持续多
Cocoa 中的NSURLRequest 类(iOS docs,OS X docs)有一个timeoutInterval 属性。文档状态 If during a connection attempt
我对 NSURLRequest(和伴奏)实现进行了尝试和测试,这对给定 URL 的 GET 和 POST 非常有效。 但是,我现在想在不更改应用程序使用的 URL 的情况下移动 URL 的目标,因此我
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 9 年前。 此问题似乎偏离主题,因为缺乏足够的信息来诊断问题。更详细地描述您的问题或 include
当使用NSURLRequest时在 iPhone 上,各种设备之间的实际性能差异是什么 NSURLRequestCachePolicy设置?我特别感兴趣的是缓存策略对用户对 UIWebView 页面显
我关注了A Cocoa application driven by HTTP data博客文章,并已能够成功使用以下 URL 获取 HTML 以在我的示例应用程序中使用: http://www.arg
我想要使用 HTTP POST 方法来与 ASPX 页面进行通信。我需要通过表单变量传递值。 如何在 Objective-C 上实现它? 最佳答案 http://www.cimgf.com/2010/
大家早上好, 我一直在尝试编写一个应用程序,从需要身份验证的远程 Web 服务执行一些 GET 操作。我的主要问题是大多数远程服务器(而且有很多)没有有效的证书。我有code to accept th
我在 iOS 应用程序中有一个 Angular Web 构建,并且想要 POST使用一些 JSON 向 native 层请求我可以用它来构建一些 native 功能。我正在使用旧的 UIWebView
我是一名优秀的程序员,十分优秀!