function uc_recurring_hosted_form_uc_paypal_wps_form_alter in UC Recurring Payments and Subscriptions 7.2
Same name and namespace in other branches
- 6.2 modules/uc_recurring_hosted/uc_recurring_hosted.module \uc_recurring_hosted_form_uc_paypal_wps_form_alter()
Paypal website payments standard process
Normally in a payment gateway we would just need to define the callback 'process': e.g. function uc_recurring_hosted_wps_process($order, $fee)
But paypal_wps is implemented by altering the checkout review form to change the form so it is submitted directly to paypal, we are using this same trick to alter the paypal form, its a messy hack but works for now.
File
- modules/
uc_recurring_hosted/ uc_recurring_hosted.module, line 579 - Provides hosted gateway specific code for recurring payments, specifically Authorize.net ARB and Paypal WPS
Code
function uc_recurring_hosted_form_uc_paypal_wps_form_alter(&$form, $form_state) {
$order = $form_state['build_info']['args'][0];
$recurring_fees = array();
// if recurring fees exist in the order
if (module_exists('uc_recurring_product')) {
// uc_recurring_products support
$recurring_fees = uc_recurring_product_get_recurring_products_in_order($order);
}
if (count($recurring_fees) > 0) {
// TODO: what do we do if someone tries to order more then one subscription??
// we will just process the first for now
$recurring_fee = $recurring_fees[0];
if (count($recurring_fees) > 1) {
drupal_set_message(t('Sorry recurring payments can only be setup for one product at a time when paying via paypal, only the first recurring payment will be setup when you click on Submit order.'), 'warning');
}
// IPN control notify URL
$data['notify_url'] = url('uc_recurring_hosted/paypal/ipn/' . $order->order_id, array(
'absolute' => TRUE,
));
$data['cmd'] = '_xclick-subscriptions';
$data['item_name'] = t('Order @order_id at !store', array(
'@order_id' => $order->order_id,
'!store' => variable_get('uc_store_name', url('<front>', array(
'absolute' => TRUE,
))),
));
// first payment
list($p, $t) = explode(' ', $recurring_fee['recurring product']->initial_charge);
$data['a1'] = sprintf("%0.2f", $order->order_total);
$data['p1'] = $p;
$data['t1'] = strtoupper($t[0]);
// recurring payments
list($p, $t) = explode(' ', $recurring_fee['recurring product']->regular_interval);
$data['a3'] = sprintf("%0.2f", $recurring_fee['recurring product']->fee_amount == 0 ? $recurring_fee['product']->price : $recurring_fee['recurring product']->fee_amount);
$data['p3'] = $p;
$data['t3'] = strtoupper($t[0]);
$data['src'] = 1;
if ($recurring_fee['recurring product']->number_intervals > 0) {
$data['srt'] = $recurring_fee['recurring product']->number_intervals;
}
$data['sra'] = 1;
// reattempt failed payments
foreach ($data as $name => $value) {
if (!empty($value)) {
$form[$name] = array(
'#type' => 'hidden',
'#value' => $value,
);
}
}
}
}