Tag Archives: HSBC Payment Methos

HSBC Payment CLASS with payer authentication service (Version 0.2.0)

6 Sep

Friends! We already suffered enough with HSBC payment and also for PASS implementation.

Finally I have made the total implementation in a single class. Before going with the source code let me explain how the PASS and API works together. We have two separate processes to complete the payment.
1. Send Credit Card information to HSBC PASS server for validation. It will return some PASS parameters.
2. Construct API XML based on PASS response and send back to HSBC to complete the payment.

But no worries! I have made the process very easy with my HSBC class.

Step – 1: Execute PASS
First create object of the class and assign following parameters and execute PASS.

// Credit Card Number
$hsbc->add_pass_field('CardholderPan',"4055011111111111");

// Exipre Date with the format mm-yy
$hsbc->add_pass_field('CardExpiration',"02/11");

// HSBC Cardholderpan
$hsbc->add_pass_field('CcpaClientId',"UKXXXXXXXXGBP");

// Currency Exponent
$hsbc->add_pass_field('CurrencyExponent',"1");

// Amount with Pound symbol.
// For Test payment it must not grater then 1
$hsbc->add_pass_field('PurchaseAmount',"£1");

// Keep it same
$hsbc->add_pass_field('PurchaseAmountRaw',"100");

// Currency Code for Pound
$hsbc->add_pass_field('PurchaseCurrency',"826");

// Return URL to API Section
$hsbc->add_pass_field('ResultUrl',"http://www.example.com/hsbc/example.php");

// Execute PASS
$hsbc->send_pass();

Step – 2: Execute API
Assign the following variables and execute API payment section. If the payment process returns “A” as a response then considers it as a successful payment.
// Set Payment mode
// For test payment set 'Y'
$hsbc->payment_mode = 'P';

// Set true to see the return XML
$hsbc->debug = false;

// Set CcpaResultsCode from PASS responds
$hsbc->ccparesultscode = $_POST['CcpaResultsCode'];

// CAVV from PASS responds
$hsbc->cavv = $_POST['CAVV'];

// XID from PASS responds
$hsbc->xid = $_POST['XID'];

// Payment information for API XML
$hsbc->xmldata = array(
// HSBC Username
"name" =>"XXXXX",
// HSBC Password
"password"=>"XXXXXX",
// HSBC Client ID
"clientid"=>"XXXXX",
// HSBC Cardholderpan
"cardholderpan"=>"UKXXXXXXXXGBP01",
// Credit Card No
"number"=>"4055011111111111",
// CVV code for Credit Card
"cvv2val"=>"345",
// Expire Date with format mm-yy
"expires"=>"02/11",
// Issue number only for SOLO and Debit Cards
"issuenum"=>"",
// Start date only for SOLO and Debit Cards
"startdate"=>"",
// Amount For test tranjection it must be 1
"total"=>"1",
// Customer Information
"email" =>"[user@store.com]",
"street1"=>"[Street 1]",
"street2"=>"[Street 2]",
"city"=>"[City]",
"stateprov"=>"[State]",
"postalcode"=>"[POST Code]",
"country"=>"[Country Code]"
);

// Execute Payment
$result = $hsbc->execute_api();

if( $result == "A")
{
echo "Pyment success";
}
else
{
echo "Payment failed";
}

Test Payment:
To execute test payment set payment_mode to Y in API section. For each test transaction the payment amount can not grater then 1.

Debug:
Set $hsbc->debug = true to see the response XML to debug your integration

Download HSBC Payment Class

HSBC payment API method (Version 0.1.0)

28 Aug

HSBC Corporation generates some tricky documents for their payment method. Hopefully they will update those as soon as possible. I had to cry “HELP HELP!” when I got their manual. 😦
I tried to contact with HSBC help desk a number of times but got more upset. Forum and blog’s also made me frustrated. I was just bouncing around them.

Here i am going to explain the total  process,
First of all, HSBC have two systems for their payment integration method  API and CPI. I solved my problem using API (Application Programmable Interface) method.
Currently API interfaces is available in – C, Java and XML.

I don’t know how dumb those guys, who developed this manual and why  they did not provide the primary elements like “POST Action URL”. After  tried several times i got from their help desk.

We have to follow these simple process to complete the API integration using XML :
Post URL: https://www.secure-epayments.apixml.hsbc.com

Step -1: Prepare an XML document  with  the payment information according to HSBC conversions.
Step-2: Send the XML document to HSBC server and retrieve  the reply instantly
Step-3: Check the status. If status is ‘A’ then consider it as a  successfull transaction.
Step-4: Update your store

Here is the  XML that I prepared to send HSBC server.

<EngineDocList>
<DocVersion DataType=”String”>1.0</DocVersion>
<EngineDoc>
<ContentType DataType=”String”>OrderFormDoc</ContentType>
<User>
<Name DataType=”String”>HSBC_USER_NAME</Name>
<Password DataType=”String”>HSBC_USER_PWD</Password>
<ClientId DataType=”S32″>HSBC_USER_ID</ClientId>
</User>
<Instructions>
<Pipeline DataType=”String”>Payment</Pipeline>
</Instructions>
<OrderFormDoc>
<Mode DataType=”String”>Y</Mode>
<Consumer>
<PaymentMech>
<Type DataType=”String”>CreditCard</Type>
<CreditCard>
<Number DataType=”String”>’ . $cradit_card_no .’</Number>
<Cvv2Val DataType=”String”>’ . $Cvv . ‘</Cvv2Val>
<Cvv2Indicator DataType=”String”>1</Cvv2Indicator>
<Expires DataType=”ExpirationDate”>’ . $exp .’</Expires>
</CreditCard>
</PaymentMech>
</Consumer>
<Transaction>
<Type DataType=”String”>PreAuth</Type>
<CurrentTotals>
<Totals>
<Total DataType=”Money” Currency=”826″>17</Total>
</Totals>
</CurrentTotals>
</Transaction>
</OrderFormDoc>
</EngineDoc>
</EngineDocList>

One important issue is, Total amount always multiplied by 100. For example, If we send amount £3530 then it will represent £35.30.

About Sand Box/Testing Mode:
Another one thing, HSBC has no SandBox. So there is not opportunity to practice except actual user account. 😦
For testing we have set <Mode DataType=”String”>Y</Mode> in XML document and for Live Transaction we have to set <Mode DataType=”String”>P</Mode>

I used CURL to send the XML to HSBC network. See the following example:

<?php
$ch = curl_init();
$url = ‘https://www.secure-epayments.apixml.hsbc.com’;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data_will_go_here);
ob_start();
$data = curl_exec($ch);
curl_close ($ch);
ob_end_clean();
?>

The return XML will available in ‘$data’ variable. There is a XML node ‘ TransactionStatus’ in return XML file from where we can determine the status of the last operation .

Now see the status of payment.

(A) Approved = Transaction was processed and accepted by the authoriser, but is not yet marked as ready for settlement
(C) Captured = Transaction is ready for settlement.
(D) Declined = Transaction was declined by the authoriser and it is unlikely that it would receive voice approval. This is also known as a hard decline.
(R) Referred = Transaction was declined by the authoriser, but it might receive voice approval. This is also known as a soft decline.
(V) Voided =Transaction has been voided.

That’s all to complate HSBC payment method. But only for proper documentation I had to suffer.

And I  thanks  MR. Paul who gave me support to do the experiment for his Finest Teddy Bear website.

Hope this post will help all of you guys.

Update September 7, 2009
Check my HSBC Paymen Class to make implement in easy way. I have implemented it with PASS(payer authentication service specification) validation.