【问题标题】:SagePay Direct Payment Integration C#SagePay 直接支付集成 C#
【发布时间】:2016-09-23 07:33:42
【问题描述】:

我正在尝试使用 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:对象引用未设置为对象的实例。] C:\dev\dotnet\VspDotNetKitAPI\SagePayIntegration.cs:93 中的 SagePay.IntegrationKit.SagePayIntegration.GetPropertyTextValue(Object request, String propertyName) C:\dev\dotnet\VspDotNetKitAPI\SagePayIntegration.cs:449 中的 SagePay.IntegrationKit.SagePayIntegration.ProcessDirectPaymentRequest(IDirectPayment paymentRequest, String directPaymentUrl) order_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(字符串事件参数)+108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 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

【问题讨论】:

  • 你能发布完整的堆栈跟踪吗?
  • 我已经编辑了问题并包含了堆栈跟踪
  • 看起来您没有设置足够的属性。你也可以尝试设置VendorTxCode吗?例如,这是您的订单号。

标签: c# asp.net .net e-commerce opayo


【解决方案1】:

您没有在付款请求上设置足够的属性,因此在尝试在内部构建请求对象时会抛出 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 中查看它的源代码。

【讨论】:

  • 谢谢.. 我需要再设置几个安静的属性。一旦我完成了所有属性,错误就消失了。
  • @leppie 哈哈,不客气。一直认为他们没有在某处提供代码很疯狂。我离圣人总部不远,也许我应该去问问:)
  • @DavidG 我必须添加对OK REPEATED 状态的支持。最后只是将OK_REPEATED 添加到枚举中并更改了无休止的复制/粘贴来处理:D
  • @leppie 哦哈哈。幸运的是,从来没有处理过这个问题。事实上,我已经有几年没有使用过这段代码了。随时提交包含更新的 PR :)
猜你喜欢
  • 1970-01-01
  • 2012-12-28
  • 2020-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-03
  • 1970-01-01
  • 2014-01-24
相关资源
最近更新 更多