Hi,
We're running Magento 2.3 CE and we're preparing to update to 2.3.1.
Is it currently possible to have Magento automatically update Paypal with the shipment tracking number that we enter into the order when it ships (we usually use UPS as our shipping company)? It's not updating now, so we've been entering tracking manually in Paypal, after we enter it into Magento.
Any tips would be greatly appreciated - thanks!
Hello @tom_drake
you need to call API for update tracking number.
check below link for same
https://devdocs.magento.com/guides/v2.3/rest/tutorials/orders/order-create-shipment.html
hope it will help you if works then mark as a solution.
We've encountered the same issue. After migrating to M2, tracking numbers don't get sent to paypal. We're using both standard Paypal express that comes with Magento and Paypal Plus (I-Ways).
Is this a bug or a misconfiguration on our end? Or do these modules simply not communicate the shipping numbers to paypal?
So far I haven't been able to find any helpful answers. I would really appreciate some feedback about how others handle this. I assume manually entering the shipping numbers into paypal isn't really a viable long term solution?
Due to Paypal using the NVP Soap to take payments, you'll need to create a REST api APP.
The APP is super easy to make in Paypal.
https://developer.paypal.com/dashboard/applications/sandbox
https://developer.paypal.com/dashboard/applications/live
Attached is the code I've just written to test the functionality. It's pretty simple, but could easily be put into an after create shipment event and check the payment method is Paypal.
You'll need to load your order with something like
$order = $this->orderRepository->get($orderId);
$getLastTransId = $order->getPayment()->getLastTransId();
$tracksCollection = $order->getTracksCollection();
$trackNumber = '';
foreach ($tracksCollection->getItems() as $track) {
$trackNumber = $track->getTrackNumber();
$trackTitle = $track->getTitle();
}
$content = [
"trackers" => [[
"transaction_id" => $getLastTransId,
"tracking_number" => $trackNumber,
"status" => "SHIPPED",
"carrier" => $trackTitle
]]
];
$pp_client_id = 'YOUR-CLIENT-ID'; $pp_secret = 'YOUR-SECRET'; $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, 'https://api.paypal.com/v1/oauth2/token'); curl_setopt($ch, CURLOPT_URL, 'https://api-m.sandbox.paypal.com/v1/oauth2/token'); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERPWD, $pp_client_id.':'.$pp_secret); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array( 'grant_type'=>'client_credentials', ))); $res_authcode = curl_exec($ch); if (empty($res_authcode)) { echo 'Unable to login'; exit; } else { $json_authcode = json_decode($res_authcode, true); $access_token = $json_authcode['access_token']; if(empty($access_token)) { echo 'No Token Provided'; exit; } else { // curl_setopt($ch, CURLOPT_URL, 'https://api.paypal.com/v1/shipping/trackers-batch');
curl_setopt($ch, CURLOPT_URL, 'https://api-m.sandbox.paypal.com/v1/shipping/trackers-batch'); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($content)); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'authorization: Bearer '.$access_token, 'content-type: application/json' )); $res_trackinfo = curl_exec($ch); if(empty($res_trackinfo)) { echo 'Unable to post shipping data'; exit; } else { $res_trackinfo = json_decode($res_trackinfo); print_r($res_trackinfo, true); exit; } } curl_close($ch); }