Search code examples
swiftparse-platformstripe-paymentsparse-cloud-codestripe-connect

Stripe Capture Charge Amount Node and Swift


I am trying to capture a charge with a different amount, but I get an error saying that there's "no such charge" and sometimes that the amount should be lower than the charge, which it is. However, the most frequent error is the "no such charge" one, although the charge is not nil.

This is the Cloud Code function in node.js:

Parse.Cloud.define("cancellationFee", function(request, response){
    stripe.charges.capture({
    charge: request.params.charge,
    amount: 500,
    destination: 500
    }, function(err, charge) {
        if(err){
                console.log(err);
                response.error(err);
        }else{
                console.log("Successfully captured cancellation fee");
                response.success("captured cancellation fee");
        }
}); 
});

Swift Code The charge variable is not nil.

PFCloud.callFunctionInBackground("cancellationFee", withParameters: ["charge": chargeID]) { (success: AnyObject?, error: NSError?) -> Void in
             if error == nil{
                 // code
             }else{
                 // code
             }
}

Solution

  • Are you sure your error isn't due to setting destination to a number? Destination should be an account id. And also should be set when creating a charge, not capturing the charge. You shouldn't be passing any additional parameters to the charge method than the charge you're capturing.

    You also shouldn't be setting the charge amount here.