Subscription - How can i sent the request from Client to Server

dineshwadhwa400
Contributor
Contributor

I am trying to create subscription from JS Call and getting Json error. Please check:  IS there any document which uses smart button and send the request to API Call and get the reponse.

JS CODE

 

paypal.Buttons({
createSubscription: function (data, actions) {
 return fetch('/AuthorizedNet/CreateSubscription/', {
method: 'post',
//headers: {
// 'content-type': 'application/json'
//}
}).then(function (res) {
//return { subscriptionID: res };
return res.json();
}).then(function (data) {
debugger;
return data.Id;
});
},
// Finalize the transaction
onApprove: function (data, actions) {
return fetch('/AuthorizedNet/PaypalCallBack/' + data.subscriptionID, {
method: 'post'
}).then(function (res) {
var a = JSON.parse(res);
return res.json();
}).then(function (details) {
// Show a success message to the buyer
alert('Transaction completed by ' + details.payer.name.given_name + '!');
});
}

}).render('#paypal-button-container');

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.