awesomemotive / easy-digital-downloads

Sell digital downloads through WordPress
https://easydigitaldownloads.com
GNU General Public License v2.0
868 stars 473 forks source link

Refactor checkout / payment processing #8691

Open ashleyfae opened 3 years ago

ashleyfae commented 3 years ago

Enhancement Request

Explain your enhancement (please be detailed)

Our checkout and payment processing flow is not in line with current payment processing standards. It was built when payment processing was a lot simpler:

These days, gateway logic is multi-step and has a lot more JavaScript.

Things on my dream list:

  1. Remove reliance on jQuery.
  2. Split up JavaScript into different functions and components that can more easily be reused by individual gateways.
  3. Improve the whole loading process (how gateway fields are loaded, etc.).
  4. A more central way of detecting a gateway error (in JavaScript) and being able to display those errors and halt the checkout process. (So many gateways have to add their own code to do this and it just leads to a lot of repetition.)
  5. Refactor edd_process_purchase_form(). Right now it's one big massive function. It would be better served as at least one class -- maybe more. In particular the validation logic should be separate from the actual processing logic.

Justification or use case

Keeping our code DRY; less repetition and "reinventing x process" in individual gateways.


Related issues:

https://github.com/easydigitaldownloads/easy-digital-downloads/issues/7366 https://github.com/easydigitaldownloads/easy-digital-downloads/issues/7188 https://github.com/easydigitaldownloads/easy-digital-downloads/issues/4220 https://github.com/easydigitaldownloads/easy-digital-downloads/issues/2222

arraypress commented 3 years ago

Somewhat related, but the 'state' field in the checkout JS is somewhat hard coded and near impossible to actually make unrequired due to this. It would be good if this was resolved too. A simpler checkout specifically aimed at digital stores would be better too, which only contains country, zip/postal code, and email/name fields.

ashleyfae commented 3 years ago

That's a good point. Not sure if it will be covered in this issue specifically, but definitely related: I want to fundamentally redesign and simplify the entire checkout form. This issue is more for gateway processing logic and error handling, but overall I think our form is quite janky and messy and could do with a lot of polish and removal of unnecessary fields.

ashleyfae commented 3 years ago

Some more thoughts:

  1. New class that ONLY handles form validation. Also a new API/ajax endpoint ONLY to trigger this class. (As opposed to now, where we have one endpoint and you "toggle" validation via a query arg.)
  2. New class that ONLY handles final form processing. This includes account creation and handing off to the gateway. This would also call the previously mentioned validation class again to double check.
  3. Another separate thing you can call that builds the final, filtered array of checkout data. This is essentially like a line item builder or something. Gives you final order total, final line items, etc. All after the filter has been applied. This would be used in point 2 above, but should also be able to be called independently so you can get this information prior to processing.