There are 3 URLs that you need to understand
1) regular paypal.com
2) sandboxed paypal and
3) developer.paypal
To create the test seller and test buyer accounts, you must be logged in with your regular pay pal account at developer.paypal
To manage and edit your test seller and test buyer accounts, you must log into them from the sandboxed.paypal URL
How to Create a Custom PayPal Check Out
Log in to your PayPal account
Tools - Click the Tools menu
All Tools - Click All Tools
Scroll to PayPal buttons and click Open
For an add-on the user is buying a single item - Choose the first option to buy a single item
Choose a button type of “Buy Now”
Add a text field for the email or domain name that the add-on will be running under
Click “Create Button”
Select and copy the code (HTML) for the new button
Paste your PayPal HTML code into your HTML
Change the target="_top" to target="_blank" so that PayPal opens in a new browser tab or window (May depend on how the user set up their browser)
To test your button, create sandboxed test credentials
https://developer.paypal.com/docs/classic/paypal-payments-standard/ht_test-pps-buttons/
To create a sandbox account:
Log in to the Developer site at https://developer.paypal.com. On the Dashboard tab, navigate to Sandbox > Accounts.
Click Create Account and populate the following fields:
https://developer.paypal.com/developer/accounts/
To test a button you need to have two accounts - A “Business” account and a “Buyer” account.
Log in to PayPal with the seller account: example-Emai...@gmail.com
YOU MUST LOG IN AT THE SANDBOXED URL
https://www.sandbox.paypal.com/us/signin/?country.x=US&locale.x=en_US
For the Test HTML:
Create a button with the steps as outlined at the top of the page
The test HTML is slightly different than the “Live” html
Add an IPN listener URL to the test SELLER PayPal account
In your PayPal account profile- Add the Apps Script Web App Url as the IPN listener page.
Go into your Profile Settings
Choose “My Selling Tools”
Click “update” in “Instant payment notifications” row
Click the “Choose IPN Settings” button
Use the test HTML to open up the PayPal log in dialog box
When prompted to log in on the PayPal payment page, log in with your test buyer account credentials for the sandbox.
In the test SELLER PayPal Developer Dashboard, under Sandbox, click Notifications.
Verify that you have received email notifications for your transactions.
The test system WILL invoke a IPN (Instant Payment Notification) but the IPN Url must be put into the test account of the facilitator (seller)
You can determine what PayPal button that your payment came from by using the
item_number
property in the object sent to the IPN. And that id value is set in your button definition in the optional "item ID"
Receive payment information from PayPal to an Apps Script Web App
NOTE: For testing, the IPN must be added to the test SELLER account.
You can create test buyer and seller accounts. These are different than your regular PayPal account. In order to run tests, you must create test account. Otherwise you’d need to make an actual payment every time that you wanted to test your payment system.
IPN or Instant Payment Notification, informs you of Payments received from Pay Pal.
You need to click on settings, then My Selling Tools, and look for Instant Payment Notifications
General Pay Pal information about the IPN listener.
PayPal has 200 or 300 pieces of information that can be accessed. Each piece of information has it’s own property name.
Important property name: txn_type Transaction type
txn_type (Transaction type) For example: express_checkout which means that a single payment was received from the express checkout. Or new_case meaning that a dispute was filed. Transaction Types
Next important property names: Payment Information Variables
The payment information property that you’ll probably want to use is payment_status which has many sub-properties indicating the payment status. Of the 12 or so sub-properties of payment_status, you’ll probably be the most interested in: Completed and Processed ; and also Denied and Failed. There is also: Pending Refunded Reversed and Voided. But, if you didn’t get the payment, then you probably won’t want to give the user access to whatever you’re selling. The goal of this article is to get a payment from PayPal. I’ll deal with the other stuff later.
Confirm to PayPal that a message was received.
There are two things that must happen from the Apps Script end to respond back to Pay Pay:
Quote:After receiving the IPN message from PayPal, your listener returns an empty HTTP 200 response to PayPal. Otherwise, PayPal resends the IPN message. This probably happens automatically and internally. I don’t think that you need to program anything for this to happen.
Quote: Your listener sends the complete message back to PayPal using HTTPS POST. Prefix the returned message with the cmd=_notify-validate variable, but do not change the message fields, the order of the fields, or the character encoding from the original message.
There is another quote that states to add the "cmd=_notify-validate" to the end, and not the beginning: Quote: After receiving an IPN message from PayPal, you must respond to PayPal with a POST message that is an exact copy of the received message but with "cmd=_notify-validate" added to the end of the message. One part of the documentation states to add the "cmd=_notify-validate" to the beginning, and another part of the documentation states to add it to the end. I just added a cmd property to the object with the value _notify-validate" and the Simulator stated that the handshake was verified.
Create and Publish an Apps Script Web App as the IPN listener page
The Web App needs a doPost() function to receive the request sent from PayPal
Add code to the Apps Script code editor - for code see:
Create an IPN listener page
In your PayPal account profile- Add the Apps Script Web App Url as the IPN listener page.
Go into your Profile Settings
Choose “My Selling Tools”
Click “update” in “Instant payment notifications” row
Click the “Choose IPN Settings” button
Note: You do not need to set your profile settings to test the Apps Script Web App, but for it to be working live, you must add the Web App url to the profile settings.
Test your IPN Listener - Which is an Apps Script Web App
You can use the IPN simulator: Docs IPN Simulator
There is a test property from the IPN simulator named: test_ipn PayPal doesn’t call it a property, they call it a variable. That variable is not included in the live IPN message.
There are 2 basic things that you must do to use the IPN Simulator. You need to add the word “sandbox” to the postback URL: https://ipnpb.sandbox.paypal.com/cgi-bin/webscr
Secondly, the Apps Script Web App must be published and functioning. That was covered above.
Next Log into the Developer part of Pay Pal: https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNSimulator/ I can not find a way to get to the IPN simulator documentation by navigating the menus. Unless you are logged in, the Dashboard is not displayed, and you can not get to the IPN Simulator
Paste your Apps Script URL into the IPN handler URL field.
Choose the Transaction type - Probably “Express Checkout”
Make sure that the latest version of your Apps Script Web App is published, or it won’t run the newest version.
If you don’t use the special test URL with “sandbox” you may get a message in the simulator that the handshake was verified, but get an INVALID response back from the POST request.
You should receive a VERIFIED response back from the handshake.