Another payment method plugin request here, this time for the (seemingly very) popular payment gateway "ClickandBuy". It's been referred to as the "European Paypal", so it seems like a good gateway to offer support for (could certainly boost redSHOP usage in Europe).
(I'll add more API resources as I discover them), and I've also discovered this
Get Instance of ClickandbuyAPI class and set class options
<?php
// Load class library
include_once("clickandbuyapi.php");
// Example Configurations:
$configs = array( 'gateway' => array(
'gateway_url' => '
eu.clickandbuy.com/newauth/http://premium-[your keys].eu.clickandbuy.com/',
'return_url' => '
www.yourwebsite.com/clickandbuy_return.php',
'sellerID' => 'your sellerId',
'tmPassword' => 'your tmPassword',
'dynkey' => '',
),
'customParams' => array('myUserId', 'myItemId'), // these parameters will be preserved.
);
// get instance
$api = ClickandbuyAPI::getInstance($configs);
?>
Generate Clickandbuy Link
<?php
// Get your ClickandBuy transaction parameters from database
$data = array(
'cb_currency' => 'EUR',
'lang' => 'en',
'cb_billing_Nation' => 'UK',
'price' => 100, // price in cent
'cb_content_name_utf' => 'Yurssite.com',
'cb_content_info_utf' => 'Yur product title',
'myUserId' => 10, // optional
'MyItemId' => 32, // optional
);
// Construct clickandbuy payment link
$url = $api->link($data);
// now you can use this link in html anchor like:
?>
<a href="<?php echo $url; ?>">Pay using ClickandBuy</a>
Check Your Transaction
Verify transaction information and store transaction data into your database with status uncommitted.
File: transaction_check.php
<?php
// verify transaction information and return all necessary data in array
$checkData = $api->check(false);
if (!empty($checkData)) {
// check and insert server transaction data into database.
/**
* ... database insert code here....
*/
// redirect to landing page for second handshake
header('Location: ' . $checkData['url']);
exit;
}
?>
Transaction Return Page
This page will call soap call isExternalBDRIDCommitted as second handshake to confirm the transaction.
File: transaction_return.php
<?php
// call soap method isExternalBDRIDCommitted and return all necessary information as array
$committed = $api->isCommitted();
if (!empty($committed)) {
// soap status
if ($committed['return'] == ture) {
/**
* ... update transaction as completed ....
*/
echo "Transaction successfull!";
} else {
/**
* ... update transaction as fault ....
*/
echo "Transaction cancelled";
}
$api->pr($committed); // dump result data
} else {
// other errors
echo "Transaction cancelled";
$api->pr($api->getErrors()); // dump errors for debug
}
?>
Tips
You can merge Transaction check and Transaction Return URL in same location. See the example below:
<?php
if (empty($_GET['result'])) {
// ... code for transaction check page ...
} else {
// ... code for transaction landing page ....
}
?>