https://github.com/javascriptdude/paypalauthintent
Example of Using PayPal AUTHORIZE Intent Using REST APIs
https://github.com/javascriptdude/paypalauthintent
Last synced: about 1 month ago
JSON representation
Example of Using PayPal AUTHORIZE Intent Using REST APIs
- Host: GitHub
- URL: https://github.com/javascriptdude/paypalauthintent
- Owner: JavaScriptDude
- License: mit
- Created: 2021-10-04T03:06:14.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-06T16:44:57.000Z (over 3 years ago)
- Last Synced: 2025-02-12T07:54:35.866Z (3 months ago)
- Language: Python
- Size: 27.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## PayPalAuthIntent
Example of Using PayPal AUTHORIZE Intent Using REST APIsThis tool is intended as a sample for consuming PayPal APIs and for testing.
This tool will simulate Auth Intent and REST calls end to end and includes google-chrome launching, watching and http callbacks from PayPal UI.
This example is coded to have the Order left in APPROVED status after the user clicks `Continue` button. The Authorization (completion) of order is left to the client such as after the user is presented with a final `Confirmation` screen. This is similar to how Spotify utilizes PayPal.
To run this, you will need an account in sandbox.paypal.com and enable REST API's
For Environment variables create file `~/.paypal/acmeinc_sandbox/.env` and put into it:
```
PP_CLIENT_ID="<>"
PP_CLIENT_SECRET="<>"
```#### Running:
```python3 main.py```### Sample Outputs:
#### User Clicked `Continue`:
```
211003-231435.937 main.py:44 - Calling PayPal REST API to create Order
211003-231437.260 main.py:56 - start_link: https://www.sandbox.paypal.com/checkoutnow?token=498032340R017683K
211003-231437.541 main.py:66 - Order 498032340R017683K is created. Loading PayPal dialog using Chrome...
You may hit `Continue`, `Cancel and return ...` or close the chrome window
211003-231437.545 helpers.py:312 - Watching for browser being closed ...
211003-231448.176 main.py:130 - WebServer called: /pp_ord_accepted?token=498032340R017683K&PayerID=5LT9QAPV5QQ7W
211003-231448.176 helpers.py:89 - Server being shut down
211003-231448.177 helpers.py:332 - Closing browser
211003-231448.902 main.py:92 - User approved the order by hitting CONTINUE
211003-231448.902 main.py:94 - Calling PayPal REST API to authorize Order ...
211003-231450.242 main.py:102 -
Order Auth Result:
- id: 498032340R017683K
- intent: AUTHORIZE
- status: COMPLETED
- create_time: 2021-10-04T03:14:36Z
- update_time: 2021-10-04T03:14:49Z211003-231450.738 main.py:111 - Order Approved and completed
211003-231450.738 main.py:114 - DONE
```#### User Clicked `Cancel and return ...`:
```
211003-231725.986 main.py:44 - Calling PayPal REST API to create Order
211003-231727.046 main.py:56 - start_link: https://www.sandbox.paypal.com/checkoutnow?token=4NV01103CF1182546
211003-231727.387 main.py:66 - Order 4NV01103CF1182546 is created. Loading PayPal dialog using Chrome...
You may hit `Continue`, `Cancel and return ...` or close the chrome window
211003-231727.390 helpers.py:312 - Watching for browser being closed ...
211003-231736.286 main.py:130 - WebServer called: /pp_ord_cancelled?token=4NV01103CF1182546
211003-231736.287 helpers.py:89 - Server being shut down
211003-231736.288 helpers.py:332 - Closing browser
211003-231736.805 main.py:76 - PayPal user cancelled or closed window
211003-231736.806 main.py:78 - Calling PayPal REST API to cancel Order ...
211003-231737.663 main.py:86 - Order Cancelled
211003-231737.664 main.py:114 - DONE
```#### User closed window:
```
211003-231803.624 main.py:44 - Calling PayPal REST API to create Order
211003-231804.732 main.py:56 - start_link: https://www.sandbox.paypal.com/checkoutnow?token=77D57926RY568931E
211003-231805.125 main.py:66 - Order 77D57926RY568931E is created. Loading PayPal dialog using Chrome...
You may hit `Continue`, `Cancel and return ...` or close the chrome window
211003-231805.129 helpers.py:312 - Watching for browser being closed ...
211003-231813.146 helpers.py:324 - Browser was closed by user
211003-231813.146 helpers.py:89 - Server being shut down
211003-231813.435 main.py:76 - PayPal user cancelled or closed window
211003-231813.435 main.py:78 - Calling PayPal REST API to cancel Order ...
211003-231814.349 main.py:86 - Order Cancelled
211003-231814.350 main.py:114 - DONE
```
Note: This usecase would be handled differently in Production as we don't have access to the browser process