summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWesley Jones2015-08-27 07:46:25 (GMT)
committerWesley Jones2015-08-27 07:46:25 (GMT)
commit869e39db6d7afe9cf98c3d3f0957ba4084198515 (patch)
tree0e74ce476b9d1856300d2b4cc4421c811a39cb1f
parentc4e9609ed59ddc71585a32ba3040aa908317c289 (diff)
Implemented logic to send the customer back to review checkout when the paypal order fails
-rw-r--r--commerce_license_billing_paypal.module79
1 files changed, 49 insertions, 30 deletions
diff --git a/commerce_license_billing_paypal.module b/commerce_license_billing_paypal.module
index 1d40c75..301231b 100644
--- a/commerce_license_billing_paypal.module
+++ b/commerce_license_billing_paypal.module
@@ -65,6 +65,7 @@ function commerce_license_billing_paypal_cron() {
// Make sure this is using the paypal subscription payment method.
if ($order->data['payment_method'] == 'paypal_ec_subscription|commerce_payment_paypal_ec_subscription') {
$payment_method = commerce_payment_method_instance_load($order->data['payment_method']);
+ dd($order->data, 'order data');
$profile_id = $order->data['commerce_paypal_ec']['profileid'];
// Build a name-value pair array to obtain recurring payment profile information from PayPal.
@@ -441,45 +442,63 @@ function commerce_license_billing_paypal_redirect_form_validate($order, $payment
);
$response2 = commerce_paypal_api_request($payment_method, $nvp2, $order);
- // Set the Recurring Profile ID.
- $order->data['commerce_paypal_ec']['profileid'] = $response2['PROFILEID'];
+ if ($response2['ACK'] == 'Success') {
- // If the user is anonymous, add their PayPal e-mail to the order.
- if (empty($order->mail)) {
- $order->mail = $response['EMAIL'];
- }
+ // Set the Recurring Profile ID.
+ dd($response2, 'response2');
+ if (empty($response2['PROFILEID'])) {
+ watchdog(
+ 'commerce_license_billing_paypal',
+ 'The PROFILEID from the Paypal response is empty for user ID: %uid.',
+ array('%uid' => $order->uid),
+ WATCHDOG_ERROR
+ );
+ }
+ else {
+ $order->data['commerce_paypal_ec']['profileid'] = $response2['PROFILEID'];
+ }
- // Create a billing information profile for the order with the available info.
- if (!empty($payment_method['settings']['update_billing_profiles'])) {
- commerce_paypal_ec_customer_profile($order, 'billing', $response, 'PAYMENTREQUEST_0_');
- }
+ // If the user is anonymous, add their PayPal e-mail to the order.
+ if (empty($order->mail)) {
+ $order->mail = $response['EMAIL'];
+ }
- // If the shipping module exists on the site, create a shipping information
- // profile for the order with the available info.
- if (module_exists('commerce_shipping') && !empty($payment_method['settings']['update_shipping_profiles'])) {
- commerce_paypal_ec_customer_profile($order, 'shipping', $response, 'PAYMENTREQUEST_0_');
- }
+ // Create a billing information profile for the order with the available info.
+ if (!empty($payment_method['settings']['update_billing_profiles'])) {
+ commerce_paypal_ec_customer_profile($order, 'billing', $response, 'PAYMENTREQUEST_0_');
+ }
- // Recalculate the price of products on the order in case taxes have
- // changed or prices have otherwise been affected.
- if ($order->data['commerce_paypal_ec']['flow'] == 'ec') {
- commerce_cart_order_refresh($order);
- }
+ // If the shipping module exists on the site, create a shipping information
+ // profile for the order with the available info.
+ if (module_exists('commerce_shipping') && !empty($payment_method['settings']['update_shipping_profiles'])) {
+ commerce_paypal_ec_customer_profile($order, 'shipping', $response, 'PAYMENTREQUEST_0_');
+ }
+
+ // Recalculate the price of products on the order in case taxes have
+ // changed or prices have otherwise been affected.
+ if ($order->data['commerce_paypal_ec']['flow'] == 'ec') {
+ commerce_cart_order_refresh($order);
+ }
- // Save the changes to the order.
- commerce_order_save($order);
+ // Save the changes to the order.
+ commerce_order_save($order);
- // If the customer completed payment using the Mark flow, then we should
- // attempt to process payment now and go back if it fails.
- if ($order->data['commerce_paypal_ec']['flow'] == 'mark') {
- $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
- $charge = $order_wrapper->commerce_order_total->value();
+ // If the customer completed payment using the Mark flow, then we should
+ // attempt to process payment now and go back if it fails.
+ if ($order->data['commerce_paypal_ec']['flow'] == 'mark') {
+ $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
+ $charge = $order_wrapper->commerce_order_total->value();
- // Attempt to process the payment.
- if (!commerce_paypal_ec_do_payment($payment_method, $order, $charge)) {
- return FALSE;
+ // Attempt to process the payment.
+ if (!commerce_paypal_ec_do_payment($payment_method, $order, $charge)) {
+ return FALSE;
+ }
}
}
+ else {
+ // Order was not successful!!
+ return false;
+ }
}
/**