IPN Issue Fixed
This commit is contained in:
parent
d6ed93bb91
commit
6b0b4b32dc
|
|
@ -2,34 +2,42 @@
|
|||
|
||||
namespace Webkul\Paypal\Helpers;
|
||||
|
||||
use Webkul\Paypal\Payment\Standard;
|
||||
use Webkul\Sales\Repositories\OrderRepository;
|
||||
use Webkul\Sales\Repositories\InvoiceRepository;
|
||||
|
||||
class Ipn
|
||||
{
|
||||
/**
|
||||
* Ipn post data
|
||||
* IPN post data.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $post;
|
||||
|
||||
/**
|
||||
* Order object
|
||||
* Standard $paypalStandard
|
||||
*
|
||||
* @var \Webkul\Paypal\Payment\Standard
|
||||
*/
|
||||
protected $paypalStandard;
|
||||
|
||||
/**
|
||||
* Order $order
|
||||
*
|
||||
* @var \Webkul\Sales\Contracts\Order
|
||||
*/
|
||||
protected $order;
|
||||
|
||||
/**
|
||||
* OrderRepository object
|
||||
* OrderRepository $orderRepository
|
||||
*
|
||||
* @var \Webkul\Sales\Repositories\OrderRepository
|
||||
*/
|
||||
protected $orderRepository;
|
||||
|
||||
/**
|
||||
* InvoiceRepository object
|
||||
* InvoiceRepository $invoiceRepository
|
||||
*
|
||||
* @var \Webkul\Sales\Repositories\InvoiceRepository
|
||||
*/
|
||||
|
|
@ -40,20 +48,24 @@ class Ipn
|
|||
*
|
||||
* @param \Webkul\Sales\Repositories\OrderRepository $orderRepository
|
||||
* @param \Webkul\Sales\Repositories\InvoiceRepository $invoiceRepository
|
||||
* @param \Webkul\Paypal\Payment\Standard $paypalStandard
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
Standard $paypalStandard,
|
||||
OrderRepository $orderRepository,
|
||||
InvoiceRepository $invoiceRepository
|
||||
)
|
||||
{
|
||||
$this->paypalStandard = $paypalStandard;
|
||||
|
||||
$this->orderRepository = $orderRepository;
|
||||
|
||||
$this->invoiceRepository = $invoiceRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function process the ipn sent from paypal end
|
||||
* This function process the IPN sent from paypal end.
|
||||
*
|
||||
* @param array $post
|
||||
* @return null|void|\Exception
|
||||
|
|
@ -80,7 +92,7 @@ class Ipn
|
|||
}
|
||||
|
||||
/**
|
||||
* Load order via ipn invoice id
|
||||
* Load order via IPN invoice id.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
|
@ -92,7 +104,7 @@ class Ipn
|
|||
}
|
||||
|
||||
/**
|
||||
* Process order and create invoice
|
||||
* Process order and create invoice.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
|
|
@ -112,13 +124,13 @@ class Ipn
|
|||
}
|
||||
|
||||
/**
|
||||
* Prepares order's invoice data for creation
|
||||
* Prepares order's invoice data for creation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function prepareInvoiceData()
|
||||
{
|
||||
$invoiceData = ["order_id" => $this->order->id,];
|
||||
$invoiceData = ['order_id' => $this->order->id];
|
||||
|
||||
foreach ($this->order->items as $item) {
|
||||
$invoiceData['invoice']['items'][$item->id] = $item->qty_to_invoice;
|
||||
|
|
@ -128,24 +140,20 @@ class Ipn
|
|||
}
|
||||
|
||||
/**
|
||||
* Post back to PayPal to check whether this request is a valid one
|
||||
* Post back to PayPal to check whether this request is a valid one.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function postBack()
|
||||
{
|
||||
if (array_key_exists('test_ipn', $this->post) && 1 === (int) $this->post['test_ipn']) {
|
||||
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
|
||||
} else {
|
||||
$url = 'https://www.paypal.com/cgi-bin/webscr';
|
||||
}
|
||||
$url = $this->paypalStandard->getIPNUrl();
|
||||
|
||||
$request = curl_init();
|
||||
|
||||
curl_setopt_array($request, [
|
||||
CURLOPT_URL => $url,
|
||||
CURLOPT_POST => TRUE,
|
||||
CURLOPT_POSTFIELDS => http_build_query(array('cmd' => '_notify-validate') + $this->post),
|
||||
CURLOPT_POSTFIELDS => http_build_query(['cmd' => '_notify-validate'] + $this->post),
|
||||
CURLOPT_RETURNTRANSFER => TRUE,
|
||||
CURLOPT_HEADER => FALSE,
|
||||
]);
|
||||
|
|
@ -161,4 +169,4 @@ class Ipn
|
|||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@
|
|||
|
||||
namespace Webkul\Paypal\Http\Controllers;
|
||||
|
||||
use Webkul\Paypal\Helpers\Ipn;
|
||||
use Webkul\Checkout\Facades\Cart;
|
||||
use Webkul\Sales\Repositories\OrderRepository;
|
||||
use Webkul\Paypal\Helpers\Ipn;
|
||||
|
||||
class StandardController extends Controller
|
||||
{
|
||||
/**
|
||||
* OrderRepository object
|
||||
* OrderRepository $orderRepository
|
||||
*
|
||||
* @var \Webkul\Sales\Repositories\OrderRepository
|
||||
*/
|
||||
protected $orderRepository;
|
||||
|
||||
/**
|
||||
* Ipn object
|
||||
* IPN $ipnHelper
|
||||
*
|
||||
* @var \Webkul\Paypal\Helpers\Ipn
|
||||
*/
|
||||
|
|
@ -62,7 +62,7 @@ class StandardController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Success payment
|
||||
* Success payment.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
|
@ -78,7 +78,7 @@ class StandardController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Paypal Ipn listener
|
||||
* Paypal IPN listener.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,4 +16,4 @@ Route::group(['middleware' => ['web']], function () {
|
|||
});
|
||||
});
|
||||
|
||||
Route::get('paypal/standard/ipn', 'Webkul\Paypal\Http\Controllers\StandardController@ipn')->name('paypal.standard.ipn');
|
||||
Route::post('paypal/standard/ipn', 'Webkul\Paypal\Http\Controllers\StandardController@ipn')->name('paypal.standard.ipn');
|
||||
|
|
|
|||
|
|
@ -5,14 +5,14 @@ namespace Webkul\Paypal\Payment;
|
|||
class Standard extends Paypal
|
||||
{
|
||||
/**
|
||||
* Payment method code
|
||||
* Payment method code.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $code = 'paypal_standard';
|
||||
|
||||
/**
|
||||
* Line items fields mapping
|
||||
* Line items fields mapping.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
|
@ -24,7 +24,7 @@ class Standard extends Paypal
|
|||
];
|
||||
|
||||
/**
|
||||
* Return paypal redirect url
|
||||
* Return paypal redirect url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -34,7 +34,20 @@ class Standard extends Paypal
|
|||
}
|
||||
|
||||
/**
|
||||
* Return form field array
|
||||
* Return paypal IPN url.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIPNUrl()
|
||||
{
|
||||
return $this->getConfigData('sandbox')
|
||||
? 'https://ipnpb.sandbox.paypal.com/cgi-bin/webscr'
|
||||
: 'https://ipnpb.paypal.com/cgi-bin/webscr';
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return form field array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
|
|
@ -89,7 +102,7 @@ class Standard extends Paypal
|
|||
}
|
||||
|
||||
/**
|
||||
* Add shipping as item
|
||||
* Add shipping as item.
|
||||
*
|
||||
* @param array $fields
|
||||
* @param int $i
|
||||
|
|
|
|||
Loading…
Reference in New Issue