-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: multiple payment methods #17
Conversation
wip: integration with Electronic Payment Profile, Payment Gateway and credit limit
23e823d
to
9484692
Compare
Quick update here - the internal wiring for both Authorize.net and Stripe supports multiple payment methods, including a credit check and calculation of fees. The desk-perspective is working, but I'm getting a Permissions error after clicking "Pay" on the Portal side. The API call goes through, but when the Journal Entry tries to save, the system seems to apply the portal user's permissions up the validation chain and throws an error. For now I also put the Customer and Supplier field back in to hold the Customer's ID in the API. This is useful to have saved somewhere separate than an electronic payment profile for the logic branch to save payment info for the current transaction only. The code creates a customer profile and a temporary payment profile (then deletes once used) - having the customer ID saved separate and being able to access it prevents it from creating another one in the API every time. The ERPNext credit limit code seemed to have an inconsistency in it - it would run a credit check as an after-save method for a Journal Entry, and ignored if the "exclude Sales Orders" option is checked. I was getting a credit limit error for any payment made if the sum total of Sales Orders were over the threshold (which is allowed with that option). I created an override so the credit check respected the Credit Limit configuration for a customer. I'm working on the Billed as Agreed - there's still some plumbing to match a payment to the payment term in the Payment Entry (required when there's a payment template on a SO/SI). |
Permissions traceback error - same for both Payment Entry and Journal Entry: Traceback (most recent call last):
File "apps/electronic_payments/electronic_payments/electronic_payments/doctype/electronic_payment_settings/stripe.py", line 365, in charge_customer_profile
process_electronic_payment(doc, data, response.id)
File "apps/electronic_payments/electronic_payments/electronic_payments/doctype/electronic_payment_settings/common.py", line 34, in process_electronic_payment
create_journal_entry(doc, data, transaction_id)
File "apps/electronic_payments/electronic_payments/electronic_payments/doctype/electronic_payment_settings/common.py", line 181, in create_journal_entry
je.save()
File "apps/frappe/frappe/model/document.py", line 309, in save
return self._save(*args, **kwargs)
File "apps/frappe/frappe/model/document.py", line 331, in _save
return self.insert()
File "apps/frappe/frappe/model/document.py", line 255, in insert
self.check_permission("create")
File "apps/frappe/frappe/model/document.py", line 196, in check_permission
self.raise_no_permission_to(permtype)
File "apps/frappe/frappe/model/document.py", line 218, in raise_no_permission_to
raise frappe.PermissionError
frappe.exceptions.PermissionError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "apps/electronic_payments/electronic_payments/electronic_payments/doctype/electronic_payment_settings/stripe.py", line 381, in charge_customer_profile
frappe.log_error(message=frappe.get_traceback(), title=f"{e.code}: {e.type}. {e.message}")
AttributeError: 'PermissionError' object has no attribute 'code' |
Permissions update: Using enqueue (with params
|
@agritheory @fproldan - permission error issue is fixed and this should be ready for a second set of eyes. I had to copy code logic one level up from I shared the test script in Slack that auto-loads payment info. Only (minor) thing not quite working is that after a successful API payment, is it's only creating the paid Journal Entry for the last customer in the loop. (The transactions all go through). May be an enqueued job thing where they're not distinguished as unique but I didn't want to hold this up trying to track it down. |
...tronic_payments/electronic_payments/doctype/portal_payment_method/portal_payment_method.json
Show resolved
Hide resolved
...tronic_payments/electronic_payments/doctype/portal_payment_method/portal_payment_method.json
Show resolved
Hide resolved
...tronic_payments/electronic_payments/doctype/portal_payment_method/portal_payment_method.json
Show resolved
Hide resolved
In the execution of the test script, I get the following errors in Stripe when tries to add a new payment method: stripe.error.CardError: Request req_2Rdte3IYnTAEvA: Sending credit card numbers directly to the Stripe API is generally unsafe. We suggest you use test tokens that map to the test card you are using, see https://stripe.com/docs/testing. To enable raw card data APIs in test mode, see https://support.stripe.com/questions/enabling-access-to-raw-card-data-apis. |
All good comments, @fproldan thanks for the thorough review - I'll start addressing these today. For the Stripe error, I didn't get that when I reinstalled, maybe I enabled something in my account to bypass it? I'll look into creating a function that uses their test card token info instead of a raw number in the test script. I guess the bigger question is what happens in production when a user enters a card number (will we have to use Stripe's UI components?)... |
Support a "Billed per Agreement" option - workflow needs more designTo be handled with a separate PR