【问题标题】:Execute a charge from existing customer with card in Stripe out of iOS使用 iOS 中 Stripe 中的卡从现有客户处执行收费
【发布时间】:2015-12-23 04:17:14
【问题描述】:

我很难弄清楚如何通过 iOS 应用程序以编程方式执行此操作。

我正在使用(除其他外)来自 github 的以下类: https://github.com/hybrdthry911/ELStripe

类:ELCharge.m

+(ELCharge *)charge{
   return [[ELCharge alloc]init];
}

(*****************code in between ************************)

 //Will attempt to charge either a customer or card. Exactly one must exist   
per charge. If multiple or neither exist an exception will be raised.
//Warning: This is the final step it will APPLY A CHARGE TO THE 
ACCOUNT.

-(void)createChargeWithCompletion:(ELChargeCompletionBlock)handler{
    [ELCharge createCharge:self completion:handler];
}

+(void)createCharge:(ELCharge *)charge completion
 (ELChargeCompletionBlock)handler{
 NSError *chargeError;
     if (![charge validForProcessingWithError:&chargeError]) {
          handler(nil,chargeError);
          return;
     }

     if (!chargeError) {
          [ELStripe executeStripeCloudCodeWithMethod:@"POST"    
           prefix:@"charges" parameters:[ELCharge 
           dictionaryForCreatingCharge:charge] completionHandler:^(id 
           jsonObject, NSError *error) {
           handler([ELCharge 
           chargeFromParseStripeDictionary:jsonObject],error);
       }];
   }
}

在 iOS 类中,我执行以下操作以创建测试费用:

//create an automatic charge in stripe from an existing customer with card   
attached to him
-(void) executeChargeInStripe:(UIButton*)sender
{

     ELCharge *charge = [ELCharge charge];

    //Assign the charge properties
    charge.customerID = @"cus_72xvQI6Q5IC9it";
    charge.currency = @"USD";
    NSNumber *chargeAmount = [NSNumber numberWithInt:111];
    charge.amountInCents = chargeAmount;


//Call ChargeMethod from Github Framework
[ELCharge createCharge:charge completion:^(ELCharge *charge, NSError 
*error)    {
    if (!error)  {
    //code for normal handling
        NSLog(@"Charge has been made successfully");
    } else {
        // error code handling
        NSLog(@"Charge NOT made");

    }
}];

}

我将其传递给以下云代码:

Parse.Cloud.define("stripeHTTPRequest", function(request, response) 
{
//Check for valid pre/suf/postfixes, if they are not there do not include    
them.
var prefix = request.params["prefix"];
var suffix = "";
var postfix = "";
var secondPostfix = "";
if (!isEmpty(request.params["suffix"])) suffix =  
    '/'+request.params['suffix'];  
if (!isEmpty(request.params["postfix"])) postfix = 
    '/'+request.params['postfix'];   
if (!isEmpty(request.params["secondPostfix"])) secondPostfix = 
    '/'+request.params['secondPostfix'];

 //call from parse to stripe done by http request as parse/stripe api 
   uncomplete
   Parse.Cloud.httpRequest(
   {
        method: request.params["method"],
        //Create URL from base url and pre/suf/postfixes
        url: 'https://'+STRIPE_API_BASE_URL + prefix + suffix + postfix + 
               secondPostfix,
               headers: {
                  'Authorization': "Bearer " + STRIPE_SECRET_KEY
                         },
              params:request.params["params"],
              success: function(httpResponse) 
             {
               //response text is a json dictionary
                 response.success(httpResponse.text);
             },
        error: function(httpResponse) 
        {
            response.error(httpResponse.text);
        }
  });
});

我现在收到以下错误: 未收费(我创建的 IOS 类的错误消息)。

我真的很惊讶我在 Parse Cloud 和 Stripe 中都没有收到错误。 例如,如果我使用已使用的令牌而不是 customerID,则两者都有错误。所以我认为连接似乎有效,也许我在 iOS 类中做错了什么。 谢谢!

【问题讨论】:

  • 您能否详细说明。你记录错误了吗?控制台日志中的解析端是否有错误?

标签: ios objective-c parse-platform stripe-payments parse-cloud-code


【解决方案1】:

您是否已将 Parse JavaScript SDK 恢复为 1.5.0?不再支持 1.5.0 之后的任何内容。

【讨论】:

    猜你喜欢
    • 2019-03-27
    • 1970-01-01
    • 2017-03-12
    • 2017-11-05
    • 1970-01-01
    • 1970-01-01
    • 2021-01-05
    • 2017-03-17
    • 1970-01-01
    相关资源
    最近更新 更多