5

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.

Community
  • 1
  • 1
Jackson
  • 1,426
  • 3
  • 27
  • 60

1 Answers1

0

First you make payment create request with

$payment = new Payment();
    $payment->setIntent("sale")
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions(array($transaction));    
$payment->create($apiContext);
  1. In create response you will get "apporval url", this approval url used to user pay there payment.

  2. Then you will receive notification from paypal via what url send in "$redirectUrls" .

  3. Here u will get "Payment id" and "payer id" using that make execute payment.

    $execution = new PaymentExecution();
    $execution->setPayerId($da['PayerID']);
    $apiContext=$this->apicontext();
    $res = $payment->execute($execution, $apiContext);
    
Alagesan
  • 349
  • 1
  • 11
  • Hi @Akagesab thanks for response. Do we code available for this to Download? – Jackson Dec 12 '16 at 02:49
  • 1
    Get Api context: https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/bootstrap.php Create Request: https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payments/CreatePayment.php Response handling: https://github.com/paypal/PayPal-PHP-SDK/blob/master/sample/payments/ExecutePayment.php – Alagesan Dec 12 '16 at 04:39