-
-
Notifications
You must be signed in to change notification settings - Fork 10
URW-180 PayPal API #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Kenneth-W-Chen
wants to merge
48
commits into
develop
Choose a base branch
from
URW-180-Paypal-API
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
URW-180 PayPal API #162
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
2f5b352
Functionality to get PayPal access token
Kenneth-W-Chen 82019cb
Created some classes corresponding to JSON objs stuff from the API (a…
Kenneth-W-Chen c0ebb0b
Added create_order function. Added some constructors for the JSON cla…
Kenneth-W-Chen 7bf6ff4
Added payment capturing, adjusted some docs, created a class for conf…
Kenneth-W-Chen 1cadce8
Added different shipping options to create_order
Kenneth-W-Chen ed0bbde
Create webhook event verify via API
Kenneth-W-Chen 29ce028
Create basic webhook handler; create basic table structure to store P…
Kenneth-W-Chen 165b198
Make table and funcs to return payment order info to button
Kenneth-W-Chen f6d90ee
Backend implementation to create orders when button is pressed
Kenneth-W-Chen 90a3948
Added discounts to items since discounted t-shirt
Kenneth-W-Chen 68c5793
Fixed pass by reference issue, removed catch clause from create_order
Kenneth-W-Chen b14bab3
Button now works
Kenneth-W-Chen 2307918
Add FK to user.id for transactions
Kenneth-W-Chen 6b0ad0e
Improved documentation. Reformatted files
Kenneth-W-Chen 2f6e627
Added Dues button. Doesn't work for t-shirts yet
Kenneth-W-Chen 21a28c0
Add drop statements
Kenneth-W-Chen d800a6e
Added webhook event handling
Kenneth-W-Chen 08291af
Define event to remove expired orders every 3 days
Kenneth-W-Chen 02c7f7c
Fixed button not showing in the Spring semester
Kenneth-W-Chen f58829b
Updated Dues handler.
Kenneth-W-Chen 904018f
Fixed order button not working with multiple items/variant names
Kenneth-W-Chen c2132bc
Dues payments are now working
Kenneth-W-Chen 4be8dcb
Fixed button not being centered on dues page
Kenneth-W-Chen ea27d10
Fixed receipt email
Kenneth-W-Chen 1e4b6f6
Improved comments and PHPDocs
Kenneth-W-Chen 2cc2f18
Add info to db for printful products
Kenneth-W-Chen aa1a977
Fix undefined variant name
Kenneth-W-Chen 7f2fdf5
Create PayPal order with Printful products
Kenneth-W-Chen 2099c01
Update Printful handler
Kenneth-W-Chen c6794c6
Add Printful handler to webhook handler
Kenneth-W-Chen 5a9a842
Remove references to IPN
Kenneth-W-Chen 2d397b2
Printful handler works now
Kenneth-W-Chen 53c039a
Fix errors in merch buy complete page
Kenneth-W-Chen 896d8a6
Fix dues shirt external IDs
Kenneth-W-Chen a3164a1
Change brand name to say UNT Robotics by default
Kenneth-W-Chen b59dfcd
Send email in discord if in dev environment
Kenneth-W-Chen 755b628
Change wording for dues+shirt payment
Kenneth-W-Chen cfe2a19
Add UPC constructor
Kenneth-W-Chen c3249a7
Rewrite payment button frontend
Kenneth-W-Chen 312c8d1
Rewrite payment button backend
Kenneth-W-Chen f2ce587
Add donation button. Change get_payment_button params
Kenneth-W-Chen c094b9d
Verify webhook events internally before externally
Kenneth-W-Chen 3850325
Adjust stuff for new data location
Kenneth-W-Chen da299f9
Fix Printful handler stuff. Remove some commented-out code
Kenneth-W-Chen 13bb621
Fix Printful order handling. Remove sql tables for paypal stuff
Kenneth-W-Chen 1f99f90
Adjust PayPalWebhookEvent to pick an API URL based on the event
Kenneth-W-Chen 7bc8af1
Merge develop into URW-180-Paypal-API
Kenneth-W-Chen 1a41955
Pass PayPal API requests through the caching system
Kenneth-W-Chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
| require_once('../api/discord/bots/admin.php'); | ||
| require_once('../api/paypal/webhook.php'); | ||
| if(isset($_POST)) { // webhook events are sent via POST | ||
| $event = new PaypalWebhookEvent(file_get_contents('php://input')); | ||
| try { | ||
| // try to verify using PayPal's API before relying on the certificate.... Consider swapping the order | ||
| try { | ||
| $verified = $event->verify_external(); | ||
| } catch (PayPalCustomApiException $e) { | ||
| $verified = $event->verify_internal(); | ||
| } | ||
| } catch(Exception $e) { | ||
| // catch all exceptions so we can send a 400 in case the issue was with PayPal | ||
| http_response_code(400); | ||
| throw $e; | ||
| } | ||
| if(!$verified) { | ||
| http_response_code(400); | ||
| error_log("Received a webhook event that couldn't be verified. Webhook event ID: {$event->payload['id']}"); | ||
| } | ||
| // http_response_code(200); // this is implied | ||
| switch($event->payload['event_type']) { | ||
| case 'CHECKOUT.ORDER.APPROVED':{ | ||
| // capture payment | ||
| require_once('../api/paypal/paypal.php'); | ||
| $paypal = new PayPalCustomApi(); | ||
| $result = json_decode($paypal->capture_payment($event->payload['resource']['id']), true); | ||
| if($result['status'] !== 'COMPLETED') { | ||
| error_log("Issue capturing payment for order ID {$event->payload['resource']['id']}. Order status is {$result['status']}"); | ||
| } | ||
| break; | ||
| } | ||
| case 'PAYMENT.CAPTURE.COMPLETED':{ | ||
| // check if printful or dues | ||
| break; | ||
| } | ||
| default:{ | ||
| error_log("Unknown or unhandled PayPal webhook event: {$event->payload['event_type']}"); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| CREATE TABLE `paypal_transactions` ( | ||
| `id` int(11) NOT NULL AUTO_INCREMENT, | ||
| `custom_id` varchar(255) NOT NULL, -- This is the ID that PayPal receives for transactions; we generate this | ||
|
Kenneth-W-Chen marked this conversation as resolved.
Outdated
|
||
| `paypal_order_id` varchar(255) NOT NULL, -- This is the order ID that PayPal generates | ||
| `creation_date` datetime NOT NULL DEFAULT NOW(), | ||
| `payment_received` bool NOT NULL DEFAULT FALSE, | ||
| `payment_receipt_date` datetime, -- The datetime when payment was captured | ||
| `item_type` enum('dues', 'prtinful_product', 'donation') NOT NULL, | ||
| `custom_data` text, -- Custom info e.g., Printful product ID | ||
| `fulfillment_status` enum('await_payment', 'fulfilled', 'error') NOT NULL DEFAULT 'await_payment', -- fulfilled means we've completed our side of the transaction (e.g., made a Printful order or gave the user Good Standing status | ||
| PRIMARY KEY (`id`) | ||
| ) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=latin1; | ||
|
|
||
| /*CREATE TABLE `paypal_orders` ( | ||
| `id` int(11) NOT NULL AUTO_INCREMENT, | ||
| `paypal_id` varchar(255) NOT NULL, -- The order ID PayPal generates | ||
| )*/ | ||
|
Kenneth-W-Chen marked this conversation as resolved.
Outdated
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.