Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get transaction details in paypal by paypal transaction ID in PHP

    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 6.29k
    Comment on it

    Hello guys, Its really helpful for integration paypal in PHP to REST API.

    To integrate it, first you have to download the PHP-paypal SDK below is the direct link
    https://github.com/paypal/PayPal-PHP-SDK/releases

    // 1. Autoload the SDK Package. This will include all the files and classes to your autoloader

    <?php
    require _DIR_ . '/PayPal-PHP-SDK/autoload.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;
    

    // 2. Provide your Secret Key. Replace the given one with your app clientId, and Secret // https://developer.paypal.com/webapps/developer/applications/myapps

        $apiContext = new \PayPal\Rest\ApiContext(
            new \PayPal\Auth\OAuthTokenCredential(
                'AVv47dfPLzgZR4AJqOM4ch60p5vkJDekn0gg9o9QaFp123vl7Dl96Tcz-RQJRJ83m1gIF12Uvedd2gOxqGz6',     // ClientID
                'EJfrUYfyf8yoXfeqyswaMmyP54exKT5L2jjhJOjJHbRkmR4-TdPBvHzOkyffdy8HKhTLpQNMThTp5HVL1f'      // ClientSecret
            )
        );
    
    if (!isset($_POST['paymentId'])){
            $response_Arr['message']='Please enter paymnet Id';
        }
        else
        {
            try {
                $payment = Payment::get($_POST['paymentId'], $apiContext);
              $obj = json_decode($payment); // $obj contains the All Transaction Information.Some of them,I have displayed Below.
              $trx_status=$obj-&gt;transactions[0]-&gt;related_resources[0]-&gt;sale-&gt;state;</p>
    
           if($trx_status == 'completed')
           {
             // Check user exist or not for payment
    
    
            }
    
    
    
    
          } catch (Exception $ex) {
          $response_Arr['message'] = $e-> getMessage();
          }
    
    }
    
    echo json_encode($response_Arr);
    die();
    

 1 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: