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?
Problem is in this line
_ajax.Data = "{token:" + JSON.stringify(token) + "}";
You should use
var token = '"Your token with S goes here"';
_ajax.Data = "{token:" + JSON.stringify(token) + "}";
because only token is not valid json and you are trying to parse it
See the Reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With