URW-180 PayPal API - #162
Conversation
… lot of this may be unnecessary)
…sses. Minor changes to PHPDocs
…irm_order (unused) Refactoring, created PayPalApplicationContext class, adjusted some error logging
Catch error from send_request in create_order
Fixed issue with create_order that threw an unexpected error
|
There's a way to verify webhook events without PayPal's API, but it does require PayPal's certificate. Is there a folder we store certs in already or should I store it in a new folder? |
…ayPal transaction items
|
I stopped having fun about 30 minutes ago |
Changed some PHPDocs
|
Me having fun now |
Receipt email is only sent once now. Removed $fields parameter from get_order_info since you can only filter for "payment_source" (which only returns the order ID). Added variant_name to paypal_items table. Added variant stuff to the order creation process Added function to tell if a webhook event is sandbox. Stopped webhook handler from trying to capture payment we already marked as captured Made a new payment button function for when the page has static info on the order (i.e., Printful products and dues page during the Spring) Moved the IPN handlers to webhook/handlers/
|
I should've made the commit message for f58829b say "Fixed some stuff" |
Minor bug fixes
Email receipt Discord message now puts the email body in a separate html file Minor comment changes/removals
|
Closing as part of reconciling prod drift. The work in these PRs was based on |
Summary
PayPalCustomApi(paypal.php) serves as an intermediary for the API. Currently implements getting an OAuth token, creating orders, getting order details, and capturing payment.paypal/api-json-objects.php)/paypal/get-orderwhich sets theLocationheader to the PayPal checkout link./paypal/event-notify.webhook/handlers. The functionality remains mostly the same.Missing functionalities (won't be added in this ticket)
ordersandwebhooksorders:Update Orders,Confirm the Order,Authorize payment for order,Add tracking information for an Order,Update or cancel tracking information for a PayPal Order.webhooks: everything exceptVerify webhook signature./merch/buy/completepage becauseOther changes
config.phpPAYPAL_SANDBOX_API_CLIENT_ID,PAYPAL_SANDBOX_API_SECRET_KEY_1,PAYPAL_SANDBOX_API_ACCOUNT,PAYPAL_SANDBOX_API_PASSWORD,PAYPAL_SANDBOX_API_SIGNATURE, andPAYPAL_SANDBOX_WEBHOOK_IDpointer-events: nonefrom.paypal-button-overlayfor the PayPal button since the button is now an actual button/template/functions/paypal.php.Testing
PayPalCustomApifunctionalityPayPalWebhookEventfunctionality/merch/productand functioninsert_paypal_item())Order process (flowchart updated 10/11/2024)
API minor notes
capture_paymentdoes not need to be filled out in this case (although you still need to pick a payment source [e.g., PayPal or Apple Pay]).Receipt notes
Usage
Create orders
Create a
PayPalCustomApiobject and callcreate_order()with the appropriate arguments. The response is JSON-encoded string with the order ID, status, and links to checkout and do other things.Example response:
{ "id": "123ABC456DEF", "status": "PAYER_ACTION_REQUIRED", "payment_source": { "paypal": {} }, "links": [ { "href": "https://api.sandbox.paypal.com/v2/checkout/orders/123ABC456DEF", "rel": "self", "method": "GET" }, { "href": "https://www.sandbox.paypal.com/checkoutnow?token=123ABC456DEF", "rel": "payer-action", "method": "GET" } ] }Capture payments
Call this function on an order ID after the payer has approved payment.
You should check the
statusfield returned by the capture request. Specifically, you wantCOMPLETED. See the docs for more details.Get order info
Call this on an order ID to get information on the order from PayPal.
The result will be a JSON-encoded string. It's a bit long, so I'm not including a sample here.
Creating a payment button
text to displayis the text displayed on the button. All letters will be capitalized.$itemsis an array of the items to send. The format for all implemented types is shown.input#paypal-items<index><key>e.g.,input#paypal-items0full_yearreturn/page/uriis the page to return the user to upon completing (approving) the order. This is relative to the website's server name (e.g., www.untrobotics.com)cancel/page/uriis the page to return the user to upon cancelling the order. It follows the same rules asreturn/page/uriTo-do