gpt4 book ai didi

c# - SagePay 直接支付集成 C#

转载 作者:太空宇宙 更新时间:2023-11-03 23:15:15 26 4
gpt4 key购买 nike

我正在尝试使用 SagePay 在我的网站上实现信用卡支付解决方案,这样我就可以在我的网站上进行付款。我正在使用 ASP.NET Web 窗体和 C#。这是我的代码:

var objSagePay = new SagePayIntegration();
var request = objSagePay.DirectPaymentRequest();

if ((request != null)) {
request.Vendor = "testVendor";
request.CardHolder = "Customer Name";
request.CardNumber = "4900000000000";
request.CardType = CardType.VISA;
request.ExpiryDate = "0119";
request.Cv2 = "123";
request.Currency = "GBP";
request.Amount = 10.0;
request.BillingAddress1 = "Test Address 1";
request.BillingAddress2 = "";
request.BillingPostCode = "412";
request.BillingCountry = "";
}

var result = objSagePay.ProcessDirectPaymentRequest(request, "https://test.sagepay.com/gateway/service/vspdirect-register.vsp");

当执行结果对象调用时,我得到 Object reference is Null。

知道我哪里做错了吗?

堆栈跟踪

[NullReferenceException: Object reference not set to an instance of an object.] SagePay.IntegrationKit.SagePayIntegration.GetPropertyTextValue(Object request, String propertyName) in C:\dev\dotnet\VspDotNetKitAPI\SagePayIntegration.cs:93 SagePay.IntegrationKit.SagePayIntegration.ProcessDirectPaymentRequest(IDirectPayment paymentRequest, String directPaymentUrl) in C:\dev\dotnet\VspDotNetKitAPI\SagePayIntegration.cs:449 orders_payment_Default.btnProceedCreditCard_Click(Object sender, EventArgs e) in Default.aspx.cs:93 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9692746 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3562

最佳答案

您没有为付款请求设置足够的属性,因此在尝试在内部构建请求对象时抛出 NullReferenceException

您可以通过调用 Validation 方法检查您是否至少设置了最小值:

var errors = objSagePay.Validation(SagePay.IntegrationKit.ProtocolMessage.DIRECT_PAYMENT,
typeof(SagePay.IntegrationKit.Messages.IDirectPayment),
request,
SagePay.IntegrationKit.ProtocolVersion.V_300);

本例中的错误对象会告诉您缺少以下值:

VendorTxCode

这是您的交易标识符,例如订单号。它必须是您进行的每笔付款的唯一值。如果您设置该值,错误应该会消失。

奖励:如果您真的对 .Net 的 SagePay 集成工具包感到困惑,您可以在我的 GitHub repository 中查看它的源代码。 .

关于c# - SagePay 直接支付集成 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37441493/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com