Uncaught error in Braintree hosted fields solution
I am implementing a hosted field Braintree-solution and I am following the documentation very exactly. And the documentation is pretty awesome I must say. Still, I get an uncaught reference error when loading the client. The error appears at the client token. Even though it is set I get an uncaught reference-error there.
Here is the end of the razor-page where the problem occurs:
var form = document.querySelector('#my-sample-form');
var submit = document.querySelector('input[type="submit"]');
var clientToken = @ViewBag.ClientToken;
braintree.client.create(
authorization: clientToken
, function (err, clientInstance)
if (err)
console.error(err);
return;
Here are the methods in the controller (even though I think that is not what generates the problem). Redirected from the post-method which picks up the billing information:
return RedirectToAction(nameof(Pay));
else
return View(order);
}
public ActionResult Pay()
var gateway = GetGetAway();
string clientToken = gateway.ClientToken.Generate();
ViewBag.ClientToken = clientToken;
return View();
public BraintreeGateway GetGetAway()
return new BraintreeGateway
Environment = Braintree.Environment.SANDBOX,
MerchantId = "xxxxxxx",
PublicKey = "xxxxxxxx",
PrivateKey = "xxxxxxxxxx"
;
[HttpPost]
public ActionResult CreatePurchase()
var gateway = config.GetGateway();
var request = new TransactionRequest
Amount = 15,
PaymentMethodNonce = Request.Query["payment_method_nonce"],
Options = new TransactionOptionsRequest
SubmitForSettlement = true
;
Result<Transaction> result = gateway.Transaction.Sale(request);
if (result.IsSuccess())
Transaction transaction = result.Target;
return View("Completed");
else
return RedirectToAction("Unsuccessful");
javascript html css asp.net-core braintree
add a comment |
I am implementing a hosted field Braintree-solution and I am following the documentation very exactly. And the documentation is pretty awesome I must say. Still, I get an uncaught reference error when loading the client. The error appears at the client token. Even though it is set I get an uncaught reference-error there.
Here is the end of the razor-page where the problem occurs:
var form = document.querySelector('#my-sample-form');
var submit = document.querySelector('input[type="submit"]');
var clientToken = @ViewBag.ClientToken;
braintree.client.create(
authorization: clientToken
, function (err, clientInstance)
if (err)
console.error(err);
return;
Here are the methods in the controller (even though I think that is not what generates the problem). Redirected from the post-method which picks up the billing information:
return RedirectToAction(nameof(Pay));
else
return View(order);
}
public ActionResult Pay()
var gateway = GetGetAway();
string clientToken = gateway.ClientToken.Generate();
ViewBag.ClientToken = clientToken;
return View();
public BraintreeGateway GetGetAway()
return new BraintreeGateway
Environment = Braintree.Environment.SANDBOX,
MerchantId = "xxxxxxx",
PublicKey = "xxxxxxxx",
PrivateKey = "xxxxxxxxxx"
;
[HttpPost]
public ActionResult CreatePurchase()
var gateway = config.GetGateway();
var request = new TransactionRequest
Amount = 15,
PaymentMethodNonce = Request.Query["payment_method_nonce"],
Options = new TransactionOptionsRequest
SubmitForSettlement = true
;
Result<Transaction> result = gateway.Transaction.Sale(request);
if (result.IsSuccess())
Transaction transaction = result.Target;
return View("Completed");
else
return RedirectToAction("Unsuccessful");
javascript html css asp.net-core braintree
1
What's the error you're receiving? What reference is uncaught? On what line? Also you might not want to post your payment gateway's private key on a public website.
– nvioli
Nov 14 '18 at 15:23
I edited the post. It is Sandbox-inloggs but I shouldn't have published them, you are right! Thank's for the suggestion! The error occurs by the clientToken.
– dodido
Nov 14 '18 at 17:56
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support at help.braintreepayments.com. Are you able to provide the full error message that is being logged in the console? I would also recommend printing the value of your client token generation value out as well as printing the value of@ViewBag.ClientTokento ensure that you are getting the intended value.
– bbusby
Nov 15 '18 at 19:17
Hi Braintree! In contact with your support I got a clientToken value that I hardcoded into the javascript and then everything loads as it should. How shall I solve this problem? It has to do with the clientToken-creation and I am following your code exactly??
– dodido
Nov 20 '18 at 8:29
add a comment |
I am implementing a hosted field Braintree-solution and I am following the documentation very exactly. And the documentation is pretty awesome I must say. Still, I get an uncaught reference error when loading the client. The error appears at the client token. Even though it is set I get an uncaught reference-error there.
Here is the end of the razor-page where the problem occurs:
var form = document.querySelector('#my-sample-form');
var submit = document.querySelector('input[type="submit"]');
var clientToken = @ViewBag.ClientToken;
braintree.client.create(
authorization: clientToken
, function (err, clientInstance)
if (err)
console.error(err);
return;
Here are the methods in the controller (even though I think that is not what generates the problem). Redirected from the post-method which picks up the billing information:
return RedirectToAction(nameof(Pay));
else
return View(order);
}
public ActionResult Pay()
var gateway = GetGetAway();
string clientToken = gateway.ClientToken.Generate();
ViewBag.ClientToken = clientToken;
return View();
public BraintreeGateway GetGetAway()
return new BraintreeGateway
Environment = Braintree.Environment.SANDBOX,
MerchantId = "xxxxxxx",
PublicKey = "xxxxxxxx",
PrivateKey = "xxxxxxxxxx"
;
[HttpPost]
public ActionResult CreatePurchase()
var gateway = config.GetGateway();
var request = new TransactionRequest
Amount = 15,
PaymentMethodNonce = Request.Query["payment_method_nonce"],
Options = new TransactionOptionsRequest
SubmitForSettlement = true
;
Result<Transaction> result = gateway.Transaction.Sale(request);
if (result.IsSuccess())
Transaction transaction = result.Target;
return View("Completed");
else
return RedirectToAction("Unsuccessful");
javascript html css asp.net-core braintree
I am implementing a hosted field Braintree-solution and I am following the documentation very exactly. And the documentation is pretty awesome I must say. Still, I get an uncaught reference error when loading the client. The error appears at the client token. Even though it is set I get an uncaught reference-error there.
Here is the end of the razor-page where the problem occurs:
var form = document.querySelector('#my-sample-form');
var submit = document.querySelector('input[type="submit"]');
var clientToken = @ViewBag.ClientToken;
braintree.client.create(
authorization: clientToken
, function (err, clientInstance)
if (err)
console.error(err);
return;
Here are the methods in the controller (even though I think that is not what generates the problem). Redirected from the post-method which picks up the billing information:
return RedirectToAction(nameof(Pay));
else
return View(order);
}
public ActionResult Pay()
var gateway = GetGetAway();
string clientToken = gateway.ClientToken.Generate();
ViewBag.ClientToken = clientToken;
return View();
public BraintreeGateway GetGetAway()
return new BraintreeGateway
Environment = Braintree.Environment.SANDBOX,
MerchantId = "xxxxxxx",
PublicKey = "xxxxxxxx",
PrivateKey = "xxxxxxxxxx"
;
[HttpPost]
public ActionResult CreatePurchase()
var gateway = config.GetGateway();
var request = new TransactionRequest
Amount = 15,
PaymentMethodNonce = Request.Query["payment_method_nonce"],
Options = new TransactionOptionsRequest
SubmitForSettlement = true
;
Result<Transaction> result = gateway.Transaction.Sale(request);
if (result.IsSuccess())
Transaction transaction = result.Target;
return View("Completed");
else
return RedirectToAction("Unsuccessful");
javascript html css asp.net-core braintree
javascript html css asp.net-core braintree
edited Nov 14 '18 at 17:52
dodido
asked Nov 14 '18 at 15:16
dodidododido
1817
1817
1
What's the error you're receiving? What reference is uncaught? On what line? Also you might not want to post your payment gateway's private key on a public website.
– nvioli
Nov 14 '18 at 15:23
I edited the post. It is Sandbox-inloggs but I shouldn't have published them, you are right! Thank's for the suggestion! The error occurs by the clientToken.
– dodido
Nov 14 '18 at 17:56
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support at help.braintreepayments.com. Are you able to provide the full error message that is being logged in the console? I would also recommend printing the value of your client token generation value out as well as printing the value of@ViewBag.ClientTokento ensure that you are getting the intended value.
– bbusby
Nov 15 '18 at 19:17
Hi Braintree! In contact with your support I got a clientToken value that I hardcoded into the javascript and then everything loads as it should. How shall I solve this problem? It has to do with the clientToken-creation and I am following your code exactly??
– dodido
Nov 20 '18 at 8:29
add a comment |
1
What's the error you're receiving? What reference is uncaught? On what line? Also you might not want to post your payment gateway's private key on a public website.
– nvioli
Nov 14 '18 at 15:23
I edited the post. It is Sandbox-inloggs but I shouldn't have published them, you are right! Thank's for the suggestion! The error occurs by the clientToken.
– dodido
Nov 14 '18 at 17:56
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support at help.braintreepayments.com. Are you able to provide the full error message that is being logged in the console? I would also recommend printing the value of your client token generation value out as well as printing the value of@ViewBag.ClientTokento ensure that you are getting the intended value.
– bbusby
Nov 15 '18 at 19:17
Hi Braintree! In contact with your support I got a clientToken value that I hardcoded into the javascript and then everything loads as it should. How shall I solve this problem? It has to do with the clientToken-creation and I am following your code exactly??
– dodido
Nov 20 '18 at 8:29
1
1
What's the error you're receiving? What reference is uncaught? On what line? Also you might not want to post your payment gateway's private key on a public website.
– nvioli
Nov 14 '18 at 15:23
What's the error you're receiving? What reference is uncaught? On what line? Also you might not want to post your payment gateway's private key on a public website.
– nvioli
Nov 14 '18 at 15:23
I edited the post. It is Sandbox-inloggs but I shouldn't have published them, you are right! Thank's for the suggestion! The error occurs by the clientToken.
– dodido
Nov 14 '18 at 17:56
I edited the post. It is Sandbox-inloggs but I shouldn't have published them, you are right! Thank's for the suggestion! The error occurs by the clientToken.
– dodido
Nov 14 '18 at 17:56
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support at help.braintreepayments.com. Are you able to provide the full error message that is being logged in the console? I would also recommend printing the value of your client token generation value out as well as printing the value of
@ViewBag.ClientToken to ensure that you are getting the intended value.– bbusby
Nov 15 '18 at 19:17
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support at help.braintreepayments.com. Are you able to provide the full error message that is being logged in the console? I would also recommend printing the value of your client token generation value out as well as printing the value of
@ViewBag.ClientToken to ensure that you are getting the intended value.– bbusby
Nov 15 '18 at 19:17
Hi Braintree! In contact with your support I got a clientToken value that I hardcoded into the javascript and then everything loads as it should. How shall I solve this problem? It has to do with the clientToken-creation and I am following your code exactly??
– dodido
Nov 20 '18 at 8:29
Hi Braintree! In contact with your support I got a clientToken value that I hardcoded into the javascript and then everything loads as it should. How shall I solve this problem? It has to do with the clientToken-creation and I am following your code exactly??
– dodido
Nov 20 '18 at 8:29
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303380%2funcaught-error-in-braintree-hosted-fields-solution%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303380%2funcaught-error-in-braintree-hosted-fields-solution%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What's the error you're receiving? What reference is uncaught? On what line? Also you might not want to post your payment gateway's private key on a public website.
– nvioli
Nov 14 '18 at 15:23
I edited the post. It is Sandbox-inloggs but I shouldn't have published them, you are right! Thank's for the suggestion! The error occurs by the clientToken.
– dodido
Nov 14 '18 at 17:56
Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support at help.braintreepayments.com. Are you able to provide the full error message that is being logged in the console? I would also recommend printing the value of your client token generation value out as well as printing the value of
@ViewBag.ClientTokento ensure that you are getting the intended value.– bbusby
Nov 15 '18 at 19:17
Hi Braintree! In contact with your support I got a clientToken value that I hardcoded into the javascript and then everything loads as it should. How shall I solve this problem? It has to do with the clientToken-creation and I am following your code exactly??
– dodido
Nov 20 '18 at 8:29