簡體   English   中英

使用iOS中的Stripe在卡中執行現有客戶的收費

[英]Execute a charge from existing customer with card in Stripe out of iOS

我很難通過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類中我做錯了什么。 謝謝!

您是否已將Parse JavaScript SDK還原為1.5.0? 不再支持1.5.0之后的任何版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM