I'm trying to create a post from an iphone using swift to my ASP API.

  public IHttpActionResult POST(FormCollection collection)
    {
        try
        { //Braintree.Test.Nonce.TransactableMasterCard

            var request = new PaymentMethodRequest
            {
                CustomerId = "thatGuy",
                PaymentMethodNonce =collection["payment_method_nonce"],
                Options = new PaymentMethodOptionsRequest
                {
                    VerifyCard = true
                }
            };

            Result<PaymentMethod> result = MerchantCredentials.Gateway.PaymentMethod.Create(request);
            return Ok();
        }
        catch
        {
            return BadRequest("Card not added");
        }
    }

Thats my api controller

 func postNonceToServer(paymentMethodNonce: String) {
let paymentURL = NSURL(string: "
http://localhost:3000/api/braintreepaymentmethod ")!
let request = NSMutableURLRequest(URL: paymentURL)
request.HTTPBody =
"payment_method_nonce=\(paymentMethodNonce)".dataUsingEncoding(NSUTF8StringEncoding)
request.HTTPMethod = "POST"

NSURLSession.sharedSession().dataTaskWithRequest(request) { (data,
response, error) -> Void in
// TODO: Handle success or failure
}.resume()
}

And that's the swift post method.

I realize that the swift is encoding the data but I'm not sure how to handle it server side.

Related posts

Recent Viewed