I'm using PHP Paypal SDK: https://github.com/paypal/PayPal-PHP-SDK
Referred PayPal REST API through PHP SDK return "Incoming JSON request does not map to API request"
In continue with https://stackoverflow.com/questions/39827032/paypal-how-to-get-payment-id-on-basis-of-transaction-id
On basis of already available Transaction Id, Need to get Payment Id
I have tried below code
require __DIR__ . '/bootstrap.php';
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\CreditCard;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
// Extra Code
use PayPal\Api\PaymentDetail;
$payer = new Payer();
$payer->setPaymentMethod('paypal');
$transaction = new PaymentDetail(
'{
"method" : "CASH",
"date" : "2014-07-06 03:30:00 PST",
"note" : "Cash received."
}'
);
$transaction->setTransactionId("3NT32794KF4824703");
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setTransactions(array($transaction));
// For Sample Purposes Only.
$request = clone $payment;
try {
$payment->create($apiContext);
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
echo $ex->getData();
}
echo "<pre>";
print_r($payment);
exit;
When i run above code it gives below kind of error
{"name":"MALFORMED_REQUEST","message":"Incoming JSON request does not map to API request","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#MALFORMED_REQUEST","debug_id":"aa8bfa2a41f1f"}
PayPal\Api\Payment Object
(
[_propMap:PayPal\Common\PayPalModel:private] => Array
(
[intent] => sale
[payer] => PayPal\Api\Payer Object
(
[_propMap:PayPal\Common\PayPalModel:private] => Array
(
[payment_method] => paypal
)
)
[transactions] => Array
(
[0] => PayPal\Api\PaymentDetail Object
(
[_propMap:PayPal\Common\PayPalModel:private] => Array
(
[method] => CASH
[date] => 2014-07-06 03:30:00 PST
[note] => Cash received.
[transaction_id] => 3NT32794KF4824703
)
)
)
)
)
How to solve above error? Please guide
Response from Paypal Tech Support
After discussion and testing with the dev teams, they confirmed that you can't use TransactionId to retrieve the PaymentId. PaymentId is generated upon initial REST API call. And this happen to REST API only.
Transaction id can be generated after REST API execute payment, Classic API [NVP/SOAP] DoEC API or normal button payment completion. It will never work to reverse the search to find the Payment Id.
As for now, the only workaround for you is to log each of the REST API request regardless if it failed or not to trace the PaymentId.
Need to Achieve: Once payment is done, it will be keep on hold. After X days it will be processed. When processed Amount will be deducted from Customer's Account.