Skip to content
Open
Show file tree
Hide file tree
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 Aug 31, 2024
82019cb
Created some classes corresponding to JSON objs stuff from the API (a…
Kenneth-W-Chen Sep 1, 2024
c0ebb0b
Added create_order function. Added some constructors for the JSON cla…
Kenneth-W-Chen Sep 2, 2024
7bf6ff4
Added payment capturing, adjusted some docs, created a class for conf…
Kenneth-W-Chen Sep 2, 2024
1cadce8
Added different shipping options to create_order
Kenneth-W-Chen Sep 2, 2024
ed0bbde
Create webhook event verify via API
Kenneth-W-Chen Sep 6, 2024
29ce028
Create basic webhook handler; create basic table structure to store P…
Kenneth-W-Chen Sep 7, 2024
165b198
Make table and funcs to return payment order info to button
Kenneth-W-Chen Sep 7, 2024
f6d90ee
Backend implementation to create orders when button is pressed
Kenneth-W-Chen Sep 8, 2024
90a3948
Added discounts to items since discounted t-shirt
Kenneth-W-Chen Sep 9, 2024
68c5793
Fixed pass by reference issue, removed catch clause from create_order
Kenneth-W-Chen Sep 9, 2024
b14bab3
Button now works
Kenneth-W-Chen Sep 9, 2024
2307918
Add FK to user.id for transactions
Kenneth-W-Chen Sep 9, 2024
6b0ad0e
Improved documentation. Reformatted files
Kenneth-W-Chen Sep 9, 2024
2f6e627
Added Dues button. Doesn't work for t-shirts yet
Kenneth-W-Chen Sep 10, 2024
21a28c0
Add drop statements
Kenneth-W-Chen Sep 10, 2024
d800a6e
Added webhook event handling
Kenneth-W-Chen Sep 11, 2024
08291af
Define event to remove expired orders every 3 days
Kenneth-W-Chen Sep 11, 2024
02c7f7c
Fixed button not showing in the Spring semester
Kenneth-W-Chen Sep 13, 2024
f58829b
Updated Dues handler.
Kenneth-W-Chen Sep 14, 2024
904018f
Fixed order button not working with multiple items/variant names
Kenneth-W-Chen Sep 14, 2024
c2132bc
Dues payments are now working
Kenneth-W-Chen Sep 15, 2024
4be8dcb
Fixed button not being centered on dues page
Kenneth-W-Chen Sep 15, 2024
ea27d10
Fixed receipt email
Kenneth-W-Chen Sep 15, 2024
1e4b6f6
Improved comments and PHPDocs
Kenneth-W-Chen Sep 16, 2024
2cc2f18
Add info to db for printful products
Kenneth-W-Chen Sep 18, 2024
aa1a977
Fix undefined variant name
Kenneth-W-Chen Sep 19, 2024
7f2fdf5
Create PayPal order with Printful products
Kenneth-W-Chen Sep 20, 2024
2099c01
Update Printful handler
Kenneth-W-Chen Sep 20, 2024
c6794c6
Add Printful handler to webhook handler
Kenneth-W-Chen Sep 20, 2024
5a9a842
Remove references to IPN
Kenneth-W-Chen Sep 20, 2024
2d397b2
Printful handler works now
Kenneth-W-Chen Sep 21, 2024
53c039a
Fix errors in merch buy complete page
Kenneth-W-Chen Sep 21, 2024
896d8a6
Fix dues shirt external IDs
Kenneth-W-Chen Sep 21, 2024
a3164a1
Change brand name to say UNT Robotics by default
Kenneth-W-Chen Sep 23, 2024
b59dfcd
Send email in discord if in dev environment
Kenneth-W-Chen Sep 24, 2024
755b628
Change wording for dues+shirt payment
Kenneth-W-Chen Sep 25, 2024
cfe2a19
Add UPC constructor
Kenneth-W-Chen Oct 11, 2024
c3249a7
Rewrite payment button frontend
Kenneth-W-Chen Oct 11, 2024
312c8d1
Rewrite payment button backend
Kenneth-W-Chen Oct 11, 2024
f2ce587
Add donation button. Change get_payment_button params
Kenneth-W-Chen Oct 11, 2024
c094b9d
Verify webhook events internally before externally
Kenneth-W-Chen Oct 11, 2024
3850325
Adjust stuff for new data location
Kenneth-W-Chen Oct 11, 2024
da299f9
Fix Printful handler stuff. Remove some commented-out code
Kenneth-W-Chen Oct 11, 2024
13bb621
Fix Printful order handling. Remove sql tables for paypal stuff
Kenneth-W-Chen Oct 12, 2024
1f99f90
Adjust PayPalWebhookEvent to pick an API URL based on the event
Kenneth-W-Chen Oct 13, 2024
7bc8af1
Merge develop into URW-180-Paypal-API
Kenneth-W-Chen Nov 17, 2024
1a41955
Pass PayPal API requests through the caching system
Kenneth-W-Chen Nov 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions paypal/event-notify.php
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']}");
}
}
}
17 changes: 17 additions & 0 deletions sql/paypal_transactions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE `paypal_transactions` (
Comment thread
Kenneth-W-Chen marked this conversation as resolved.
Outdated
`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
Comment thread
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
)*/
Comment thread
Kenneth-W-Chen marked this conversation as resolved.
Outdated