Integrating a payment Checkout Stripe
.
Used JavaScript Stripe handler, to apply Stripe charge on the transaction.
After charging the customer, it returns token. Using this token we can proceed for Actual payment.
And here is the AJAX call to Payment functionality:
var StripeHelper =
{
payProceed: function (token) {
try {
var _ajax = new AjaxHelper("/Services/Service.asmx/PaymentProceed");
_ajax.Data = "{token:" + JSON.stringify(token) + "}";
_ajax.OnInit = function () { PageHelper.loading(true); };
_ajax.OnSuccess = function (data) {
console.log(data.d);
PageHelper.loading(false);
window.location('/payment-success');
};
_ajax.Init();
}
catch (e) {
PageHelper.loading(false);
}
}
}
Here is Web Method on my TEST server, which passes token to Stripe server:
[WebMethod(EnableSession = true)]
public string PaymentProceed(string token)
{
Session["PAYMENT_MODE"] = PaymentContants.PaymentVia.Stripe;
var myCharge = new StripeChargeCreateOptions();
myCharge.AmountInCents = 100;
myCharge.Currency = "USD";
myCharge.Description = "Charge for property sign and postage";
myCharge.TokenId = token;
string key = "sk_test_Uvk2cH***********Fvs"; //test key
var chargeService = new StripeChargeService(key);
StripeCharge stripeCharge = new StripeCharge();
//Error is coming for below line -->
stripeCharge = chargeService.Create(myCharge);
//No token found
return stripeCharge.Id;
}
If I POST AJAX call on POSTMAN, it shows
unexpected 's' in JSON.
What it means in general, and in this case specifically?
_ajax.Data
? Don't you need quotes around the stringified token? – Lycopodium_ajax.Data
is simply a token: alphanumeric key. And I think quotes are not required if stringify is done. – Accompanyapplication/json
and that is why the issue occurs. There is acode
button which will show you sample code for curl as shown in i.sstatic.net/2FQYO.png. Do that an add a-v
aftercurl
to enabled verbose mode. Then execute that command in terminal and share the output of the same in your question – Possession_ajax.Data = "{ \"token\": \"" + token + "\"}";
– Farriery