function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Erin KuhnErin Kuhn 

PayPal IPN messages via FormAssembly are not updating the Salesforce Opportunity record

I have a form on FormAssembly which includes making a payment using PayPal. When PayPal sends the IPN that payment has completed, FormAssembly sends the IPN to a custom URL which is https://atsu.secure.force.com/apply.

In Salesforce, I have an APEX class called IPNHandlerController and it has this in the body:
User-added image
FormAssembly creates an Opportunity record and populates the FormAssembly_ID when the record is created. 

I also have a VisualForce page called IPNHandler. It has the following: 
User-added image

I have created a site and the URL is https://atsu.secure.force.com/apply. The Active Site Home Page is IPNHandler.

To summarize, it should work as follows: 
1. FormAssembly creates the Opportunity record with the FormAssembly_ID
2. FormAssembly sends user to PayPal.
3. User pays on PayPal. PayPal sends IPN to FormAssembly.
4. FormAssembly sends IPN to Salesforce "site" at URL of https://atsu.secure.force.com/apply
4. IPNHandler calls IPNHandlerController which updates the "Paid" field to true

All of this works EXCEPT the PayPal information is not coming through and the Paid field on Opportunity is not being set to true. So basically, FormAssembly is creating the Opportunity record with the FormAssembly_ID, but after they pay, the PayPal IPN message is not updating the Opportunity record to make the Paid field true. Is there something wrong in my APEX code, or something I may be missing? I have checked the permission settings for the guest user and they seem correct. 

 
Erin KuhnErin Kuhn
I have figured some additional information out from the debug log. From what I can tell, it acts like it can't find the custom param, but that ID does exist in an opportunity record. Below is the debug log for the Guest user. I also added the screenshot of the FormAssembly_ID field showing the custom param value it looks for in this log does exist. 
42.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
16:36:49.5 (5633301)|USER_INFO|[EXTERNAL]|00536000008yFJH|application@atsu.force.com|Greenwich Mean Time|GMTZ
16:36:49.5 (5696704)|EXECUTION_STARTED
16:36:49.5 (5703061)|CODE_UNIT_STARTED|[EXTERNAL]|06636000006v7Dr|VF: /apex/IPNHandler
16:36:49.5 (76992164)|PUSH_TRACE_FLAGS|[EXTERNAL]|01p3600000JSPMG|IPNHandlerController|APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
16:36:49.5 (77197776)|SYSTEM_MODE_ENTER|true
16:36:49.5 (77847408)|HEAP_ALLOCATE|[72]|Bytes:3
16:36:49.5 (77918864)|HEAP_ALLOCATE|[77]|Bytes:152
16:36:49.5 (77942121)|HEAP_ALLOCATE|[342]|Bytes:408
16:36:49.5 (77963097)|HEAP_ALLOCATE|[355]|Bytes:408
16:36:49.5 (77985955)|HEAP_ALLOCATE|[467]|Bytes:48
16:36:49.5 (78021501)|HEAP_ALLOCATE|[139]|Bytes:6
16:36:49.5 (78048026)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:92
16:36:49.5 (78083364)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:7
16:36:49.5 (78089529)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:2
16:36:49.5 (78123403)|METHOD_ENTRY|[1]|01p3600000JSPMG|IPNHandlerController.IPNHandlerController()
16:36:49.5 (78138471)|STATEMENT_EXECUTE|[1]
16:36:49.5 (78145726)|STATEMENT_EXECUTE|[1]
16:36:49.5 (78167918)|METHOD_EXIT|[1]|IPNHandlerController
16:36:49.5 (78252296)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
16:36:49.5 (78267881)|VARIABLE_SCOPE_BEGIN|[32]|this|IPNHandlerController|true|false
16:36:49.5 (78339754)|VARIABLE_ASSIGNMENT|[32]|this|{}|0x38c2fc08
16:36:49.5 (78357276)|STATEMENT_EXECUTE|[1]
16:36:49.5 (78361222)|STATEMENT_EXECUTE|[30]
16:36:49.5 (78371092)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:6
16:36:49.5 (79948064)|STATEMENT_EXECUTE|[32]
16:36:49.5 (79991829)|POP_TRACE_FLAGS|[EXTERNAL]|01p3600000JSPMG|IPNHandlerController|APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
16:36:49.5 (80105351)|PUSH_TRACE_FLAGS|[EXTERNAL]|01p3600000JSPMG|IPNHandlerController|APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
16:36:49.5 (80175428)|HEAP_ALLOCATE|[EXTERNAL]|Bytes:8
16:36:49.5 (80188631)|VARIABLE_SCOPE_BEGIN|[3]|this|IPNHandlerController|true|false
16:36:49.5 (80219603)|VARIABLE_ASSIGNMENT|[3]|this|{}|0x38c2fc08
16:36:49.5 (80236490)|STATEMENT_EXECUTE|[3]
16:36:49.5 (80238866)|STATEMENT_EXECUTE|[4]
16:36:49.5 (80240551)|STATEMENT_EXECUTE|[4]
16:36:49.5 (80242383)|STATEMENT_EXECUTE|[5]
16:36:49.5 (80262064)|HEAP_ALLOCATE|[50]|Bytes:5
16:36:49.5 (80286066)|HEAP_ALLOCATE|[56]|Bytes:5
16:36:49.5 (80301180)|HEAP_ALLOCATE|[64]|Bytes:7
16:36:49.5 (80451106)|HEAP_ALLOCATE|[5]|Bytes:861
16:36:49.5 (80496391)|VARIABLE_SCOPE_BEGIN|[5]|pageRef|System.PageReference|true|false
16:36:49.5 (80939698)|VARIABLE_ASSIGNMENT|[5]|pageRef|"/apex/IPNHandler?business=tuition%40atsu.edu&charset=windows-1252&custom=https%3A%2F%2Fwww.tfaforms.com%2Fresponses%2Fview%2F111878364&discount=0.00&first_name=Erin&insurance_amount=0.00&invoice=TFA-PP-111878364&ipn_track_id=ad240c5993cec&item_name1=Application+Fee&item_number1=CGHS-AppFee&last_name=Waddle&mc_currency=USD&mc_fee=0.01&mc_gross=0.01&mc_gross_1=0.01&notify_version=3.8&num_cart_items=1&payer_email=erinkuhn%40atsu.edu&payer_id=WZS3ZKY5K595G&payer_status=unverified&payment_date=14%3A46%3A00+May+17%2C+2018+PDT&payment_fee=0.01&payment_gross=0.01&payment_status=Completed&payment_type=instant&protection_eligibility=Ineligible&quantity1=1&receipt_id=2917-5032-5881-1034&receiver_email=controllers%40atsu.edu&receiver_id=42ETU3V74HA22&resend=true&residence_country=US&shipping_discount=0.00&shipping_method=Default&transaction_subject=&txn_id=68677725A37246227&txn_type=cart&verify_sign=AGu.hbwMxRXoqDiyy-IJNOnULnvNA2Qa.dQ8rsI-YMxtYYuPpq.Ia4xN"|0x381b4828
16:36:49.5 (80967803)|STATEMENT_EXECUTE|[7]
16:36:49.5 (81029674)|HEAP_ALLOCATE|[7]|Bytes:841
16:36:49.5 (81063380)|HEAP_ALLOCATE|[7]|Bytes:6
16:36:49.5 (81110304)|VARIABLE_SCOPE_BEGIN|[7]|paramCustom|String|false|false
16:36:49.5 (81140432)|VARIABLE_ASSIGNMENT|[7]|paramCustom|"https://www.tfaforms (29 more) ..."
16:36:49.5 (81149890)|STATEMENT_EXECUTE|[8]
16:36:49.5 (81155088)|HEAP_ALLOCATE|[8]|Bytes:70
16:36:49.5 (81174655)|HEAP_ALLOCATE|[8]|Bytes:4
16:36:49.5 (81203738)|HEAP_ALLOCATE|[8]|Bytes:7
16:36:49.5 (83156640)|SOQL_EXECUTE_BEGIN|[8]|Aggregations:0|SELECT Id, paid__c FROM Opportunity WHERE FormAssemblyID__c = :tmpVar1
16:36:49.5 (163586689)|SOQL_EXECUTE_END|[8]|Rows:0
16:36:49.5 (163625688)|HEAP_ALLOCATE|[8]|Bytes:4
16:36:49.5 (163644322)|HEAP_ALLOCATE|[8]|Bytes:0
16:36:49.5 (163729918)|HEAP_ALLOCATE|[8]|Bytes:4
16:36:49.5 (163753793)|HEAP_ALLOCATE|[8]|Bytes:37
16:36:49.5 (163844690)|HEAP_ALLOCATE|[8]|Bytes:46
16:36:49.5 (163885080)|VARIABLE_SCOPE_BEGIN|[23]|e|Exception|true|false
16:36:49.5 (164063886)|VARIABLE_ASSIGNMENT|[23]|e|"common.apex.runtime.impl.ExecutionException: List has no rows for assignment to SObject"|0x47f12377
16:36:49.5 (164081211)|STATEMENT_EXECUTE|[23]
16:36:49.5 (164085088)|STATEMENT_EXECUTE|[25]
16:36:49.5 (164143567)|USER_DEBUG|[25]|DEBUG|System.QueryException: List has no rows for assignment to SObject
16:36:49.5 (164164484)|STATEMENT_EXECUTE|[26]
16:36:49.5 (164219272)|POP_TRACE_FLAGS|[EXTERNAL]|01p3600000JSPMG|IPNHandlerController|APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
16:36:49.172 (172334646)|CUMULATIVE_LIMIT_USAGE
16:36:49.172 (172334646)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 1 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

16:36:49.172 (172334646)|CUMULATIVE_LIMIT_USAGE_END

16:36:49.5 (172395833)|CODE_UNIT_FINISHED|VF: /apex/IPNHandler
16:36:49.5 (173683859)|EXECUTION_FINISHED

User-added image
Erin KuhnErin Kuhn
Line 41: Contains the custom variable (you have to look at it in the popped out view
Line 51: Shows the query it tries to run to find that form id
Line 62: Shows there were no results found from the query ran. 
Erin KuhnErin Kuhn
After working on this issue for 4 days, I am posting my solution so if you have the same issue, you will not have to go through the pain that I did. I have determined that it was not working, because the formassembly url id that PayPal had, started with https, but the formassembly url id that was being created in Salesforce started with http and no s. Once I updated it, the IPN message was successfully marking the custom "Paid" field as true.
Christina Johnson 25Christina Johnson 25
Can anyone explain to me how to update Salesforce domain to have the HTTPS instead of just HTTP, as Erin mentions above?
 
Dawn Amory 15Dawn Amory 15
I was also struggling with this and my issue wasn't the URL in the FormAssemblyID field (which is updated in the connector is Form Assembly) but with the actual PayPal connector in Form Assembly.  At the bottom of the connector, there is a Payment Notifications setting, Send the PayPal payment notification (IPN) to a different URL (advanced setting) needs to be checked and your site address needs to inputted there.  Hope this helps someone!
Erin KuhnErin Kuhn
Christina, I am not sure if you are referring to the site that I am talking about in this issue, but if so, when you edit the site there is a configuration setting called "Upgrade all requests to HTTPS". I have this checked so it is using https not just http. Hope this helps! User-added image