Hi,
Here’s what I did. No doubt there’s a better way
(I’ll assume you’re okay to the point of getting the Shopkeeper orderform correctly called.
- For the gateway code, I used what is found here :
http://www.phpfour.com/blog/2009/02/php-payment-gateway-library-for-paypal-authorizenet-and-2checkout/
- I created the following folder
assets/snippets/payments
and put the contents of the ZIP file found at the location above there. So that is where Paypal.php,
PaymentGateway.php, et. al. live.
- In MODx, I created a snippet called
shk_paypal
- The contents of the snippet are what was referred to above. But I’ll include it again here anyway :
<?php
//MattC start
//function sendOrderToPayPal() {
global $modx;
$base_dir = $modx->config['rb_base_dir'];
$dbname = $modx->db->config['dbase'];
$dbprefix = $modx->db->config['table_prefix'];
$mod_table = $dbprefix."manager_shopkeeper";
$mod_config_table = $dbprefix."manager_shopkeeper_config";
$reportTpl = $_SESSION['reporttpl'] ? $_SESSION['reporttpl'] : $fields['reportTpl'];
$userLogged = isset($_SESSION['webValidated']) ? true : false;
//Get online payment info
$order_id = $_SESSION['shk_order_id'];
$fields['payment'] = $_SESSION['shk_payment_method'];
$price = $_SESSION['shk_order_price'];
$currency = $_SESSION['shk_currency'];
$userId = $_SESSION['shk_order_user_id'];
require_once $base_dir."snippets/payment/PaymentGateway.php";
require_once $base_dir."snippets/payment/Paypal.php";
// Create an instance of the paypal library
$myPaypal = new Paypal();
// Specify your paypal email
$myPaypal->addField('business', 'your_developer_paypal_test_store_email');
// Specify the currency
$myPaypal->addField('currency_code', 'USD');
// Specify the url where paypal will send the user on success/failure
$myPaypal->addField('return', 'http://your_MODx_website/index.php?id=88');
$myPaypal->addField('cancel_return', 'http://your_MODx_website/index.php?id=95');
// Specify the url where paypal will send the IPN
$myPaypal->addField('notify_url', 'http://your_MODx_website/index.php?id=96');
$user = $modx->userLoggedIn();
$userId = $user['id'];
$user_purchase_query = $modx->db->select("*", $dbprefix."web_user_settings", "webuser = $userId", "", "");
if($modx->db->getRecordCount($user_purchase_query)>0){
// Specify the product information
$myPaypal->addField('item_name', $order_id);
$myPaypal->addField('amount', $price);
$myPaypal->addField('item_number', $userId);
// Specify any custom value
$myPaypal->addField('custom', 'SHK test '.$userId);
}
// Enable test mode if needed
$myPaypal->enableTestMode();
// Let's start the train!
$myPaypal->submitPayment();
return true;
//}
//MattC end
?>
(You’ll see that a lot of the values that I used for the fields don’t make a lot of sense. I was just trying to get info going out and back. Also, I’ve never been clear on how the IPN page is supposed to work...)
- Over in the document pane, I created a new document whose content is
It’s document ID is 97.
- On my orderform, I changed my call to go to the paypal snippet document instead of the thank you page. So
"gotoid" was changed to 97 :
[!Shopkeeper? &lang=`en` ¤cy=`USD` &cartType=`full` &orderFormPage=`[*id*]`!]
[!eForm? &formid=`shopOrderForm`&tpl=`shopOrderForm`&report=`shopOrderReport`&vericode=`1`&ccsender=`1`&gotoid=`97`&subject=`SHK order`&eFormOnBeforeMailSent=`populateOrderData`&eFormOnMailSent=`sendOrderToManager`!]
(The thank you/cancel pages are dealt with in the shk_paypal snippet)
Finally, note that this is set up so that you have to be logged in as a webuser in order to send an order as the code I pulled from Shopkeeper (if I remember correctly) queries the database for order info that has been entered.
I think that’s it. Hope this helps. Feedback/discussion would be appreciated, particularly as it appears this payment gateway class can handle more than just Paypal.
Regards,
MattC