Search code examples
c#jsone-commercerealex-payments-api

Realex HPP request -custom field


I'm trying to send a custom field to realex to use upon successful response. The field in question is a json array.

[{"InvoiceId":7,"AmountPaid":180,"SucessfulPayment":false}]

The problem I face is upon response the array is truncated to [{. I have this working by base 64 encoding the array but feel its a bit heavy and would rather send the raw json. I'm also concerned there may be a character restriction on the field length's which would get eaten up quick. If there's no restriction on length I'll probably go base 64.

Update

Code as requested.

JSON array passed into request object

[{"InvoiceId":7,"AmountPaid":180,"SucessfulPayment":false}]

realex response returning

[{

Code:

<%@ Page Language="C#" AutoEventWireup="true" 
CodeBehind="RealexRedirectTestPay.aspx.cs"
Inherits="SmartClubOnline.RedirectTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body onload="document.form.submit();">
    <div class="content">
        <form name="form" 
action="https://hpp.sandbox.realexpayments.com/pay" method="post">
        <asp:Literal ID="MERCHANT_ID" runat="server" />
        <asp:Literal ID="SECRET_ID" runat="server" />
        <asp:Literal ID="CLUB_NAME" runat="server" />
        <asp:Literal ID="ORDER_ID" runat="server" />
        <asp:Literal ID="CURRENCY_ID" runat="server" />
        <asp:Literal ID="CURRENCY" runat="server" />
        <asp:Literal ID="AMOUNT" runat="server" />
        <asp:Literal ID="TIMESTAMP" runat="server" />
        <asp:Literal ID="MEMBER_ID" runat="server" />
        <asp:Literal ID="MEMBER_USERNAME" runat="server" />
        <asp:Literal ID="MEMBER_EMAIL" runat="server" />
        <asp:Literal ID="INVOICE_ID" runat="server" />
        <asp:Literal ID="MEMBERPURSEID" runat="server" />
        <asp:Literal ID="SHA1HASH" runat="server" />
        <asp:Literal ID="TempOrderNumber" runat="server" />
        <asp:Literal ID="PromoRow" runat="server" />
        <asp:Literal ID="DELAYEDSETTLEMENTON" runat="server" />
        <asp:Literal ID="CREDITCARD_SHG_AMT" runat="server" />
        <asp:Literal ID="DEBITCARD_SHG_AMT" runat="server" />
        <asp:Literal ID="AUTO_SETTLE_FLAG" runat="server" />
        <asp:Literal ID="MERCHANT_RESPONSE_URL" runat="server" />
        <!--<input type="hidden" name="AUTO_SETTLE_FLAG" value="1" />-->
        <h3>
            Redirecting you to our Payment Provider</h3>
        <p>
            You are being securely redirected to our payment provider...Please Wait...</p>
        <!-- uncomment if you want the user to click a button to continue. Also remove the onload function in the Body tag -->
        <!-- <p><input type="submit" name="submit" value="continue to payment provider" /></p> -->
        </form>
    </div>
</body>
</html>

Server side request:

            MERCHANT_ID.Text = "<input type=\"hidden\" name=\"MERCHANT_ID\" 
value=\"" + merchantID + "\" />";
            SECRET_ID.Text = "<input type=\"hidden\" name=\"SECRET_ID\" 
value=\"" + sharedSecret + "\" />";
            CLUB_NAME.Text = "<input type=\"hidden\" name=\"CLUB_NAME\" 
value=\"" + CLUBNAME + "\" />";
            ORDER_ID.Text = "<input type=\"hidden\" name=\"ORDER_ID\" 
value=\"" + orderID + "\" />";
            CURRENCY.Text = "<input type=\"hidden\" name=\"CURRENCY\" 
value=\"" + currencyCode + "\" />";
            CURRENCY_ID.Text = "<input type=\"hidden\" name=\"CURRENCY_ID\" 
value=\"" + currencyCode + "\" />";
            AMOUNT.Text = "<input type=\"hidden\" name=\"AMOUNT\" value=\"" 
+ amount + "\" />";
            TIMESTAMP.Text = "<input type=\"hidden\" name=\"TIMESTAMP\" 
value=\"" + timestamp + "\" />";
            MEMBER_ID.Text = "<input type=\"hidden\" name=\"MEMBER_ID\" 
value=\"" + MEMBERID + "\" />";
            MEMBER_USERNAME.Text = "<input type=\"hidden\" 
name=\"MEMBER_USERNAME\" value=\"" + MEMBERUSERNAME + "\" />";
            MEMBER_EMAIL.Text = "<input type=\"hidden\" 
name=\"MEMBER_EMAIL\" value=\"" + MEMBEREMAIL + "\" />";
            INVOICE_ID.Text = "<input type=\"hidden\" name=\"INVOICE_ID\" 
value=\"" + INVOICEID + "\" />";
            MEMBERPURSEID.Text = "<input type=\"hidden\" 
name=\"MEMBERPURSEID\" value=\"" + "0" + "\" />";
            SHA1HASH.Text = "<input type=\"hidden\" name=\"SHA1HASH\" 
value=\"" + hash + "\" />";
            AUTO_SETTLE_FLAG.Text = "<input type=\"hidden\" 
name=\"AUTO_SETTLE_FLAG\" value=\"" + AUTOSETTLEFLAG + "\" />";
            DELAYEDSETTLEMENTON.Text = "<input type=\"hidden\" 
name=\"DELAYEDSETTLEMENTON\" value=\"" + DELAYEDSETTLEFLAG + "\" />";
            CREDITCARD_SHG_AMT.Text = "<input type=\"hidden\" 
name=\"CREDITCARD_SHG_AMT\" value=\"" + CREDITCARD_SHG + "\" />";
            DEBITCARD_SHG_AMT.Text = "<input type=\"hidden\" 
name=\"DEBITCARD_SHG_AMT\" value=\"" + DEBITCARD_SHG + "\" />";
            MERCHANT_RESPONSE_URL.Text = "<input type=\"hidden\" 
name=\"MERCHANT_RESPONSE_URL\" value=\"" + _realexResponseURL + "\" />";

Failing code in realex response:

if (Request.Form["INVOICE_ID"] != null)
   INVOICEID = Request.Form["INVOICE_ID"].ToString();
else
    StaticOps.AddErrorToLog("FORM.INVOICE_ID : ", "VALUE NULL", 
"RealexResponse");

Solution

  • Apologies for the delay in getting back to you, didn't see the notification of your response. On the POST in, the HPP won't accept the inverted commas and truncates at that point in the string.

    Could you try url encoding the string on the way out and decoding when the response comes back? The max length of a custom field on the HPP is 255. Or you could just url encode the inverted commas. Hopefully that suits your needs. Please let me know if not.

    Best,

    Seán MacDomhnall

    Realex Payments