Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal - Get transaction details for recurring profile

On making the TransactionSearch request I receive the list of the transactions with the TRANSACTIONID field for the transactions, corresponding to the recurring payments, in the form e.g. "I-BRPN2RUD8W0G" (current is fake).

For the rest transactions - I get usual 17 single-byte alphanumeric string. That means, that for recurring payments PayPal returns ProfileID, but not TransactionID.

As a result when I request the GetTransactionDetails with this transaction id passed to PayPal I receive valid details for ordinary payments and ERROR with the message "The transaction id is not valid" for the case of recurring payments.

like image 465
Serhij Blotskyy Avatar asked Apr 03 '15 10:04

Serhij Blotskyy


2 Answers

You will need to set IPN as suggested by Sanjiv. You can get the fields as per IPN Variables. In case of refund you will also need to use parent_txn_id

If you are new with this and finding tough, you can use IPN listener class and then integrate below code

$listener = new IpnListener();

try {
    $verified = $listener->processIpn();
} catch (Exception $e) {
    return Log::error($e->getMessage());
}

if ($verified) {

$data = $_POST;
$user_id = json_decode($data['custom'])->user_id;

$subscription = ($data['mc_gross_1'] == '10') ? 2 : 1;

$txn = array(
    'txn_id'       => $data['txn_id'],
    'user_id'      => $user_id,
    'paypal_id'    => $data['subscr_id'],
    'subscription' => $subscription,
    'expires'      => date('Y-m-d H:i:s', strtotime('+1 Month')),
);

Payment::create($txn);

} else {
    Log::error('Transaction not verified');
}

Save this file code in file let say, ipn.php and now assign web path for this file in your paypal account.

PS: make sure your IPN file is on publicly accessible URL. Do not use local or restricted server.

like image 53
Mukesh Ram Avatar answered Nov 11 '22 15:11

Mukesh Ram


You have to set IPN in your Paypal merchant account (specially for recurring payments), Which sends you back a transaction details when a recurring payment happens, from there you can get $_POST['txn_id'] which is your TRANSACTIONID if $_POST['txn_type'] is recurring_payment. Save the details in your database and then you can call GetTransactionDetails method when you need transaction details. More

like image 1
Sanjeev Avatar answered Nov 11 '22 13:11

Sanjeev