透明重定向与Braintree与asp.net 4,0 [英] Transparent Redirect with Braintree with asp.net 4,0
问题描述
Hello All,
我正在尝试在我的某个webform应用程序中实现信用卡付款的透明重定向。有没有人有过使用braintree付款的经历?我想在网上关注他们的资料,但他们都在MVC。如何通过asp .Net(C#)使用透明重定向来处理任何信用卡交易?你介意帮我入门还是给我提供一些样品?
提前谢谢
Hello All,
I am trying to implement the transparent redirect for credit card payments in one of my webform applications. Has anyone experience with working braintree payments before? I am trying to follow their materials online but they are all in MVC. How would I use a transparent redirect to process any credit card transactions through asp .Net (C#)? Would you mind helping me getting started or provide me with some samples?
Thanks in advance
推荐答案
嘿我在真正的刺中了黑暗在这...理论上它应该编译,但我无法测试这个,因为我没有脑力......树...无论......帐户。
Mvc Index.cshtml网页表单版本Default.aspx
- 注意,我是非常懒惰而且没有查找如何调用Web表单变量...剃须刀的方式(这是美丽的顺便说一句)就是@ SessionUtils.Instance.TrData。我认为应该是<%SessionUtils.Instance.TrData /%>或者什么...我假设你要求网页表单代码你至少知道如何调用.aspx文件中的变量。
Hey i took a real stab in the dark at this...in theory it "should" compile but i have no way of testing this as i dont have a brainfort...tree...whatever...account.
Mvc Index.cshtml web forms Version Default.aspx
--Note, im being severly lazy and not looking up how to call web forms variables...the razor way (which is beautiful btw) is simply @SessionUtils.Instance.TrData. I think it should be something like <% SessionUtils.Instance.TrData /%> or something...im assuming since you are requesting web forms code you at least know how to call a variable in the .aspx file.
<html>
<head>
<style type='text/css'>label {display: block;} input {margin-bottom: 10px;}</style>
</head>
<body>
<h1>Braintree Credit Card Transaction Form</h1>
<form id='payment-form' action='//Call to SessionUtils.Instance.TransparentRedirectUrl' method='POST'>
<input type='hidden' name='tr_data' value='//Call To SessionUtils.Instance.TrData' />
<div>
<h2>Credit Card</h2>
<label for='braintree_credit_card_number'>Credit Card Number</label>
<input type='text' name='transaction[credit_card][number]' id='braintree_credit_card_number' value='4111111111111111'></input>
<label for='braintree_credit_card_exp'>Credit Card Expiry (mm/yyyy)</label>
<input type='text' name='transaction[credit_card][expiration_date]' id='braintree_credit_card_exp' value='12/2015'></input>
</div>
<input class='submit-button' type='submit' />
</form>
</body>
</html>
Codebehind o f Default.aspx.cs
Codebehind of Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SessionUtils.Instance.TrData = Constants.Gateway.Transaction.SaleTrData(
new TransactionRequest
{
Amount = 1000.00M,
Options = new TransactionOptionsRequest
{
SubmitForSettlement = true
}
},
"http://localhost:49283/result"
);
SessionUtils.Instance.TransparentRedirectURL = Constants.Gateway.TransparentRedirect.Url;
}
}
//This was specified in braintree demo mvc 3 project
public class Constants
{
public static BraintreeGateway Gateway = new BraintreeGateway
{
Environment = Braintree.Environment.SANDBOX,
PublicKey = "your_public_key",
PrivateKey = "your_private_key",
MerchantId = "your_merchant_id"
};
}
//Im more of an mvc 3 guy and they used viewdata/viewbag for hold some of their data. I found it easiest to just use a singleton class
// It may not be the best way or the "webforms" way but hey...it works.
public class SessionUtils
{
#region Singleton
private const string SESSION_SINGLETON_NAME = "Singleton_502E69E5-668B-E011-951F-00155DF26207";
private Sessions()
{
}
public static Sessions Instance
{
get
{
if (HttpContext.Current.Session[SESSION_SINGLETON_NAME] == null)
{
HttpContext.Current.Session[SESSION_SINGLETON_NAME] = new Sessions();
}
return HttpContext.Current.Session[SESSION_SINGLETON_NAME] as Sessions;
}
}
#endregion
public object TrData { get; set; }
public object TransparentRedirectURL { get; set; }
public string Message { get; set; }
}
}
结果/ Index.shtml到WebForms ..我们称之为结果。 aspx
Result/Index.shtml to WebForms..we'll call it Result.aspx
<html>
<body>
<h1>Transaction Response</h1>
<ul>
<li>Status - //Call to SessionUtils.Instance.Message</li>
</ul>
</body>
</html>
Result.aspx.cs代码落后
Code behind for Result.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Result<transaction> result = Constants.Gateway.TransparentRedirect.ConfirmTransaction(Request.Url.Query);
if (result.IsSuccess())
{
Transaction transaction = result.Target;
SessionUtils.Instance.Message = transaction.Status;
}
else
{
SessionUtils.Instance.Message = string.Join(", ", result.Errors.DeepAll());
}
}
}
}</transaction>
如果你有任何关于这个代码的问题,请让我知道...我不知道我可能有多大帮助我的大脑文件和techincal详细信息,因为我从来没有使用过它们但这应该/可能让你指向正确的方向对于webforms ...也许......
If you have any question about this code please let me know...i dont know how much help i may be with the brain stuff documentation and techincal details on that as ive never used them but this should/may get you pointed in the right direction for webforms...maybe...
private Sessions()
{
}
无法正常工作
not working
这篇关于透明重定向与Braintree与asp.net 4,0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!