Incomplete sale status after completing the full payment – WP e-Commerce

Versions
Wordpress – 3.5.3
Wp eCommerce – 3.8.12.1

Problem

Somedays back, i ran into an issues with Wp e-Commerce plugin. I always got Incomplete sales even after completing the full payment. I had IPN enabled but the status was never marked as accepted payment. I tried with many combination of settings but without luck.

I started searching support forums and found that these issue has never been resolved. So i had no choice than rectifying each steps myself.

After loosing much time, i found that it was due to use of different currency in paypal account and ecommerce website.  When paypal accepts different currency than associated with the seller’s account, it settles the amount with your primary currency. In this case, the first IPN sends payment status as pending even though the payment is completed. Paypal then sends second IPN after settling the payment in your primary currency.

Solution

So, i made changes in the code to fix this.

Locate this file : wp-content/plugins/wp-e-commerce/wpsc-merchants/paypal-standard.merchant.php

Search for this code: Line : 481 – 491

switch ( strtolower( $this->paypal_ipn_values['payment_status'] ) ) {
case 'pending':
$status = 2;
break;
case 'completed':
$status = 3;
break;
case 'denied':
$status = 6;
break;
}

And replace with this:

switch ( strtolower( $this->paypal_ipn_values['payment_status'] ) ) {
case 'pending':
if ($this->paypal_ipn_values['pending_reason'] == 'multi_currency'):
$status = 3;
else :
$status = 2;
endif;
break;
case 'completed':
$status = 3;
break;
case 'denied':
$status = 6;
break;
}

Explanation
When paypal send status as pending for multi-currency, it also send pending reason. If the pending reason is multi_currency, it means that the payment has been received but the payment settlement hasn’t been done yet. So we updated the payment status as Completed if the pending reason is multi_currency.

Hope this helps. Please do let me know in comments. Thanks