function uc_recurring_hosted_paypal_wpp_update_form_submit 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_paypal_wpp_update_form_submit()
Update form submission callback
_state
Parameters
unknown_type $form:
Return value
unknown_type
File
- modules/
uc_recurring_hosted/ uc_recurring_hosted.module, line 1101 - Provides hosted gateway specific code for recurring payments, specifically Authorize.net ARB and Paypal WPS
Code
function uc_recurring_hosted_paypal_wpp_update_form_submit($form, $form_state) {
$fee = uc_recurring_fee_user_load($form_state['values']['rfid']);
$order = uc_order_load($fee->order_id);
$order->payment_details = $form_state['values']['cc_data'];
//update the billing details
$order->billing_first_name = $form_state['values']['billing_first_name'];
$order->billing_last_name = $form_state['values']['billing_last_name'];
$order->billing_street1 = $form_state['values']['billing_street1'];
$order->billing_street2 = $form_state['values']['billing_street2'];
$order->billing_city = $form_state['values']['billing_city'];
$order->billing_country = $form_state['values']['billing_country'];
$order->billing_zone = $form_state['values']['billing_zone'];
$order->billing_postal_code = $form_state['values']['billing_postal_code'];
uc_order_save($order);
$cc_type = '';
if (isset($order->payment_details['cc_type'])) {
switch (strtolower($order->payment_details['cc_type'])) {
case 'amex':
case 'american express':
$cc_type = 'Amex';
break;
case 'visa':
$cc_type = 'Visa';
break;
case 'mastercard':
case 'master card':
$cc_type = 'MasterCard';
break;
case 'discover':
$cc_type = 'Discover';
break;
}
}
if (empty($cc_type)) {
$cc_type = _uc_paypal_card_type($order->payment_details['cc_number']);
if ($cc_type === FALSE) {
drupal_set_message(t('The credit card type did not pass validation.'), 'error');
watchdog('uc_recurring', 'Could not figure out credit card type @type', array(
'@type' => $order->payment_details['cc_type'],
), WATCHDOG_ERROR);
return FALSE;
}
}
// Build an NVP request.
$nvp_request = array(
'CREDITCARDTYPE' => $cc_type,
'ACCT' => $order->payment_details['cc_number'],
'EXPDATE' => date('mY', mktime(0, 0, 0, $order->payment_details['cc_exp_month'], 1, $order->payment_details['cc_exp_year'])),
);
if (!empty($order->billing_first_name)) {
$nvp_request['FIRSTNAME'] = substr($order->billing_first_name, 0, 25);
}
if (!empty($order->billing_last_name)) {
$nvp_request['LASTNAME'] = substr($order->billing_last_name, 0, 25);
}
if (!empty($order->billing_street1)) {
$nvp_request['STREET'] = substr($order->billing_street1, 0, 100);
}
if (!empty($order->billing_street2)) {
$nvp_request['STREET2'] = substr($order->billing_street2, 0, 100);
}
if (!empty($order->billing_city)) {
$nvp_request['CITY'] = substr($order->billing_city, 0, 40);
}
if (!empty($order->billing_country)) {
$billing_country = uc_get_country_data(array(
'country_id' => $order->billing_country,
));
if ($billing_country === FALSE) {
$billing_country = array(
0 => array(
'country_iso_code_2' => 'US',
),
);
}
$nvp_request['COUNTRYCODE'] = $billing_country[0]['country_iso_code_2'];
if (!empty($order->billing_zone)) {
$nvp_request['STATE'] = uc_get_zone_code($order->billing_zone);
}
}
if (!empty($order->billing_postal_code)) {
$nvp_request['ZIP'] = check_plain($order->billing_postal_code);
}
if (!empty($order->billing_phone)) {
$nvp_request['PHONENUM'] = substr($order->billing_phone, 0, 20);
}
if ($message = uc_recurring_hosted_paypal_wpp_update($order, $fee, $nvp_request)) {
drupal_set_message(t('Your account has been updated successfully.'));
$form_state['redirect'] = 'user/' . $form_state['values']['uid'];
}
else {
drupal_set_message(t('Your account failed to update due to an error with your card information. Please try again or contact us for assistance.'), 'error');
}
}