# How to (programatically) take an action based on PayPal results using PayPal Standard Addon \[RESOLVED\]

**URL:** <https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105>\
**Category:** Get Help\
**Tags:** caching, paypal, siteground, ipn, gform\_post\_payment\_action\
**Created:** [March 2, 2021, 3:37pm UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105 "2021-03-02T15:37:43Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![SleeperTech](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sleepertech/32/1187_2.png) [@SleeperTech](https://community.gravityforms.com/u/SleeperTech)\
**Post date:** [March 2, 2021, 3:37pm UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/1 "2021-03-02T15:37:43Z")

</div>

Greetings,

I have a plugin which needs to automatically set a checkbox value when a payment is made via PayPal Standard Addon. For example, upon successful payment (only), the field would show as checked:

`[x] User has paid.`

I see several hooks and after reading I’m thinking I need to use [gform\_post\_payment\_action](https://docs.gravityforms.com/gform_post_payment_action/) because it lets me capture the status of the payment.

Problem is I’m testing via PayPal Sandbox and I cannot figure out HOW to capture _ **any** _ data.

I tried this … (in functions.php)

```
add_action( 'gform_post_payment_action', function ( $entry, $action ) {
	var_dump( $action );
	die();
}, 10, 2 );

```

…which failed miserably as the payment completed and showed me nothing (ajax?).

Also, PayPal is not returning to my page. I have to manually click “Return to Merchant”. What am I missing?

please advise.

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [March 2, 2021, 5:10pm UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/2 "2021-03-02T17:10:26Z")

</div>

Hi @SleeperTech

PayPal Standard communicates payment status changes to your site using IPN requests. To take custom actions based on the information reported by PayPal you will want to use the following hook [gform\_paypal\_post\_ipn - Gravity Forms Documentation](https://docs.gravityforms.com/gform_paypal_post_ipn/)  
The $\_POST variable gives you access to all the information received including the payment status.

​​​​I would recommend you to enable logging on the Forms \> Settings page and then on the Forms \> Settings \> Logging page ensure that Gravity Forms Core and any add-ons are enabled and set to log all messages.

> **[Logging and Debugging - Gravity Forms Documentation](https://docs.gravityforms.com/logging-and-debugging/)**
>
> For quite a while, enabling logging within Gravity Forms has been a go-to method for debugging any issues within Gravity Forms. As of Gravity Forms version 2.2, logging functionality has been moved from a separate add-on to becoming a core feature of...

Then you can add custom logging statements to ensure your custom function is running when expected and dump information from key parts of your code to the log (that is way better than using var\_dump() ), check instructions here: [Custom Logging Statements - Gravity Forms Documentation](https://docs.gravityforms.com/custom-logging-statements/#writing-to-the-core-log)

Regarding to the Auto Return feature, that’s controled by the PayPal site not by the add-on, you should find an Auto Return setting in your PayPal account. I’m sure PayPal support can help you further with this if you’re unable to find the setting.

---

<div class="post-metadata">

**Author:** ![SleeperTech](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sleepertech/32/1187_2.png) [@SleeperTech](https://community.gravityforms.com/u/SleeperTech)\
**Post date:** [March 2, 2021, 6:19pm UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/3 "2021-03-02T18:19:32Z")

</div>

What a great answer! Thank you, good Sir …and thanks for pointing me to the right hook!

+1 for the intro to GF Logging & Debugging. I will be on that today!

Preston

---

<div class="post-metadata">

**Author:** ![SleeperTech](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sleepertech/32/1187_2.png) [@SleeperTech](https://community.gravityforms.com/u/SleeperTech)\
**Post date:** [March 3, 2021, 5:10am UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/4 "2021-03-03T05:10:47Z")

</div>

Greetings @sacom

So based on the reading I’ve turned on logging and i can generate logs. However, I have been completely unsuccessful at writing anything to the log. Tried the code below (in `functions.php`), checked the logs for `Gravity Forms Core` and for `Gravity Forms PayPal Standard Add-On` and nothing was written to the logs.

The test code:

```
add_action( 'gform_paypal_post_ipn', 'blackopz_gf_log_test', 10, 4 );
function blackopz_gf_log_test( $entry, $feed, $transaction_id, $amount ) {
	GFCommon::log_debug( __METHOD__. '(): BlackOpz_Entry => ' . print_r( $entry, true ) );
	GFCommon::log_debug( __METHOD__. '(): BlackOpz_Feed => ' . print_r( $feed, true ) );
}

```

Not showing up. What am I missing.

Please Advise.

Preston

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [March 3, 2021, 9:05am UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/5 "2021-03-03T09:05:13Z")

</div>

Preston, gform\_paypal\_post\_ipn will run only if your site receives an IPN request from PayPal. Is your PayPal log showing any IPN request being received since you added the snippet?

---

<div class="post-metadata">

**Author:** ![SleeperTech](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sleepertech/32/1187_2.png) [@SleeperTech](https://community.gravityforms.com/u/SleeperTech)\
**Post date:** [March 3, 2021, 2:31pm UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/6 "2021-03-03T14:31:02Z")

</div>

Well, it’s still working as expected. Transactions are completing, etc. It’s setup using an IPN so nothing has changed. Plus, I am seeing logs, I just cannot add anything to it.

1. I added this to my Beaver Builder (child) theme’s `function.php` file:

2. Then I completed a PayPal transaction.

3. Then I opened the `Gravity Forms Core` log and did a search for “_is this thing on?_” and found nothing. Also did a search for IPN and found nothing (in core log).

4. Then I checked the `Gravity Forms PayPal Standard Add-On` log and searched for “_is this thing on?_” and found nothing. But I did find a boatload of references to IPN. See snippet:

So yeah, I would say IPN is on and working. **But still no custom messages showing**.

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [March 3, 2021, 4:03pm UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/7 "2021-03-03T16:03:08Z")

</div>

Your PayPal log should contain a line like this:

> Executing functions hooked to gform\_paypal\_post\_ipn

I’m not seeing it above. Make sure that you’re running latest version of the add-on.

The following would add _Testing my function…_ to the PayPal log:

```
add_action( 'gform_paypal_post_ipn', 'test_ipn_received', 10, 4 );
function test_ipn_received( $ipn_post, $entry, $feed, $cancel ) {
  gf_paypal()->log_debug( __METHOD__. '(): Testing my function...' );
}

```

It’s working for me on a default WordPress installation without caching or other third-party plugins or custom code.

---

<div class="post-metadata">

**Author:** ![SleeperTech](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sleepertech/32/1187_2.png) [@SleeperTech](https://community.gravityforms.com/u/SleeperTech)\
**Post date:** [March 3, 2021, 5:24pm UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/8 "2021-03-03T17:24:31Z")

</div>

So now this is making zero sense to me.

1. I have IPN setup correctly.

2. I completed a transaction via PayPal.

3. The form entry shows the transaction with the following details:

4. Then I checked the logs (both core and PayPal Standard) and (using a search) I did not see the string `gform_paypal_post_ipn`.

5. Now, I am seeing **all kinds of references** to IPN _this_ and IPN _that_.

For example…

```
2021-03-02 19:36:40.335932 - DEBUG --> GFPayPal::callback(): IPN message successfully verified by PayPal 
2021-03-02 19:36:40.335988 - DEBUG --> GFPayPal::get_entry(): IPN message has a valid custom field: 242|c8e534f6a348c3041eab30dce9d28e77 

```

1. But again, **not** the string `gform_paypal_post_ipn`.

So if the **lack** of the string `gform_paypal_post_ipn` indicates that IPN is **not** working, then **how** can there possibly be a completed transaction (both in PayPal Sandbox and in the GF Entry)?

---

<div class="post-metadata">

**Author:** ![SleeperTech](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sleepertech/32/1187_2.png) [@SleeperTech](https://community.gravityforms.com/u/SleeperTech)\
**Post date:** [March 3, 2021, 5:30pm UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/9 "2021-03-03T17:30:52Z")

</div>

Also, although I cannot test sandbox on localhost, I disabled the PayPal feed and tested the following (see code) just to see if I could use any hook to write anything to the log.

```
add_action( 'gform_after_submission', 'blackopz_gf_log_test', 10, 4 );
function blackopz_gf_log_test( $entry, $feed, $transaction_id, $amount ) {
	GFCommon::log_debug( '(): BlackOpz ' );
	GFCommon::log_debug( __METHOD__. '(): BlackOpz Entry => ' . print_r( $entry, true ) );
}

```

**It Works!** …on **localhost**!

So I tried the exact same code on SiteGround (GrowBig) server and … **FAIL**!

**Observations**

1. So PayPal or not, I cant seem to write **anything** to the site while on SiteGround. To be clear, logs **are** generated on SiteGround, but **custom** logging -PayPal or Not- continuously **FAILS** to write to the log.
2. While I cannot test PayPal on LocalHost, I **can** confirm that **custom logging does at least work** …locally.

…weird.

---

<div class="post-metadata">

**Author:** ![sacom](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sacom/32/53_2.png) [@sacom](https://community.gravityforms.com/u/sacom)\
**Post date:** [March 3, 2021, 6:24pm UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/10 "2021-03-03T18:24:42Z")

</div>

> So if the **lack** of the string `gform_paypal_post_ipn` indicates that IPN is **not** working

That’s not correct, all the IPN stuff that you see on the log and the fact that you’re seeing the entry payment details being updated indicate the IPN handling is working.

The only issue here is that something on the SiteGround hosted site preventing your custom code from running. As pointed previously, I can’t replicate the issue you’re experiencing on a default WordPress installation, you have also confirmed the same basic logging code that is working on your localhost copy is not working on the SiteGround site, so the issue is tied to something on that site setup or the host.

I would recommend you to start by excluding your form page from cache to ensure you always work with fresh resources: [https://www.siteground.com/tutorials/wordpress/sg-optimizer/supercacher/](https://www.siteground.com/tutorials/wordpress/sg-optimizer/supercacher/) (scroll down to Exclude URLs).

You can also try using a custom functions plugin instead of adding the code to your theme functions.php file. Here’s a helper plugin to do that: [Pluginception – WordPress plugin | WordPress.org](https://wordpress.org/plugins/pluginception/)

If none of the above helps, I would recommend you to perform a full conflict test: [https://docs.gravityforms.com/conflict-testing-using-health-check-plugin/](https://docs.gravityforms.com/conflict-testing-using-health-check-plugin/)

---

<div class="post-metadata">

**Author:** ![SleeperTech](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sleepertech/32/1187_2.png) [@SleeperTech](https://community.gravityforms.com/u/SleeperTech)\
**Post date:** [March 4, 2021, 12:37am UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/11 "2021-03-04T00:37:11Z")

</div>

> [@sacom](#):
>
> That’s not correct, all the IPN stuff that you see on the log and the fact that you’re seeing the entry payment details being updated indicate the IPN handling is working.

I figured as much. Esp. since i’m seeing transactions. But that begs the question: so **why** no `gform_paypal_post_ipn` in the logs? …just curious.

> [@sacom](#):
>
> The only issue here is that something on the SiteGround hosted site preventing your custom code from running.

Agreed. Local tests bear that out.

> [@sacom](#):
>
> I would recommend you to start by excluding your form page from cache to ensure you always work with fresh resources: [SuperCacher Controls in SG Optimizer Tutorial](https://www.siteground.com/tutorials/wordpress/sg-optimizer/supercacher/) (scroll down to Exclude URLs).

Will do. …more news as it happens.

> [@sacom](#):
>
> You can also try using a custom functions plugin instead of adding the code to your theme functions.php file.

Interesting plugin. …and by the great **Otto** , no less 🙂. But I already have starter plugin code. But **does it matter** that the tests are in `functions.php`? True, for best practices, I normally like to keep my functions.php file pretty clean. But now I’m curious as to _why_ you are recommending a plugin? More for best practices (I assume), than for performance/functionality, correct? …or no?

> [@sacom](#):
>
> If none of the above helps, I would recommend you to perform a full conflict test

Well, since its pretty much working locally, I will leave this as you have stated: last resort.

**Next Up**

I’m gonna give the caching options a shot (thanks again for going the extra mile in providing the links 😉). If tweaking the cache fails, I’m off to SiteGround Support. I will report back.

Thanks again for your help!

Preston

---

<div class="post-metadata">

**Author:** ![SleeperTech](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/sleepertech/32/1187_2.png) [@SleeperTech](https://community.gravityforms.com/u/SleeperTech)\
**Post date:** [March 6, 2021, 12:52am UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/12 "2021-03-06T00:52:46Z")

</div>

**Final Update:**

> [@sacom](#):
>
> The only issue here is that something on the SiteGround hosted site preventing your custom code from running.

The “something” in fact did turn out to be cache related. SiteGround is …well… “aggressive” with their caching (and their speedy sites show it). Also, they recently moved [from Static Cache to NGINX Direct Delivery](https://www.siteground.com/blog/nginx-direct-delivery/) . Don’t know what role that may have played.

Their solution was to (temporarily) completely disable dynamic caching for the site. Then re-enable once testing is done. A bit _draconian_, maybe …but it worked. When time permits, I’m going to test whether I can be a bit more “strategic” using the SG Optimizer (I did exclude the form page, but it had no effect).

But for now, I’m back in business!

Thanks to all who helped!

Preston

---

<div class="post-metadata">

**Author:** ![chrishajer](https://sea2.discourse-cdn.com/flex020/user_avatar/community.gravityforms.com/chrishajer/32/88_2.png) [@chrishajer](https://community.gravityforms.com/u/chrishajer)\
**Post date:** [March 6, 2021, 1:10am UTC](https://community.gravityforms.com/t/how-to-programatically-take-an-action-based-on-paypal-results-using-paypal-standard-addon-resolved/8105/13 "2021-03-06T01:10:20Z")

</div>


