3
votes

Current Status

I'm quite new to PayPal and I'm currently integrating chained adaptive payments on our website. Already successfully called the PAY API call via the .NET SDK. Money (sandbox enviroment) will be correctly transferred to each participants of this payment (sender, primary and secondary receiver).

Requirement

My goal is to execute vital tasks after the payment is successful (update DB, send mail, ...) or has been cancelled (clean up stuff, ...).

Possible solutions

1) First approach was to create the payment with actionType set to CREATE, redirect the user to paypal.com (wait for approval), redirect user back to website and execute the payment and then perform the vital tasks. But it seems not to work, the payment will be paid and is COMPLETED before the second redirect.

2) Another possible solution would be to get the preapproval from the user, redirect back to the website and execute the payment. Haven't tried this solution yet, don't think that this is best practice.

3) Call PAY with actionType set to "PAY" and wait for IPN. Haven't tried that either, because it is quite difficult to test it locally (even though I've already found this question: Paypal Sandbox Test Tool IPN Simulator in Localhost).

Question(s)

Which solution is best practice? I guess the recommended solution would be to wait for an IPN?

If I'am using IPN how long is the average response time after a payment has been completed? Seconds, minutes, hours? I know it depends on the load of the PayPal webservers and that there are 15 retries over 4 days, but what are some real world numbers?

Can I store additional information (e.g. UserId) about the sender in a payment (besides the memo field) which I then get back in an IPN?

1

1 Answers

0
votes

Here is how I do it.

When I'm going to initiate PayPal payment (before I send a request to obtain TOKEN), I create new transaction in my database and set it's status to PENDING. In transaction table I also have userID column, which is foreign key to user table. This way I connect transaction with user.

When transaction is created in my table, I use transactionId value, and save it to PHP $_SESSION variable.

Please note that if you want to support recurring payments, you can provide transactionId to PayPal. This you can do by setting:

"PAYMENTREQUEST_0_INVNUM"=>$transaction->id.

This value will be sent when PayPal sends you IPN request after recurring payment happens.

Go back now to the story

User is redirected to PayPal, and when user fills PayPal username and password, and when user confirms payment details, user will be redirected back to your website and you have to call DoExpressCheckoutPayment to make payment itself.

If the result of DoExpressCheckoutPayment API call is success, that means that transaction was successful and you have money. At this point, you can send email, notifications, or any other important action.

$transactionResponse=$paypal->request("DoExpressCheckoutPayment",$requestParams);//Execute transaction
    if(is_array($transactionResponse) && $transactionResponse["ACK"]=="Success")//Payment was successfull
    {
        //Send email
        //Notify user 
        //Do other important changes in database, for example mark this transaction as successful
        Transactions()::model()->updateByPk($_SESSION['transactionId'],array('status'=>'SUCCESS');
    }

IMPORTANT NOTE FOR RECURRING PAYMENTS: PayPal can/will send you several IPN requests for the same recurring transaction which means that you have to add logic which will chekc weather specific IPN request is already processed or not. Usually I do it in a way to check weather status of my transaction with transactionId is 'PENDING' or 'SUCCESSFUL'.