1

I have this function set up on Cloud Code that is called twice sometimes thrice, although I intend to have it run once. It is called through a Swift function.

Cloud Code

Parse.Cloud.define("customer", function(request, response) {
    var user = request.user;
    stripe.customers.create({ email: request.params.useremail }).then(function(customer) {
        user.set("cusToken", customer.id);
    return user.save(null, { useMasterKey: true });
    }).then(function(result) {
    console.log("Customer created");
    }, function(err) {
        console.log(err);
        response.error(err);
    });
});

Swift

PFCloud.callFunctionInBackground("customer", withParameters: ["useremail": self.userEmailAdressTextField.text ?? ""], block: { (success: AnyObject?, error: NSError?) -> Void in
                            })
Dups
  • 201
  • 1
  • 2
  • 12
  • Could you set a global variable when the function is processing, then unset it once it is done? Then the first line of the function checks it and just returns if it is set, otherwise allows the function to continue. – big_water Dec 27 '16 at 19:20
  • @big_water Thank you for your response. I am a bit confused to be honest. What variable should I make global? – Dups Dec 28 '16 at 19:38
  • can you show some of the code that is calling this CloudCode function? – big_water Dec 30 '16 at 13:51
  • @big_water I added it to the question – Dups Feb 16 '17 at 12:13
  • Possible duplicate of [Cloud Code function running twice](https://stackoverflow.com/questions/33524450/cloud-code-function-running-twice) – Dielson Sales May 25 '17 at 17:34

0 Answers0