Skip to content

Commit

Permalink
Merge pull request #42148 from blaggacao/payments/pr-4
Browse files Browse the repository at this point in the history
feat(payment): add more payment channels than just email and phone (think: chat)
  • Loading branch information
ruthra-kumar authored Jul 18, 2024
2 parents a912e07 + c39a44c commit 79a46ad
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"label": "Currency"
},
{
"depends_on": "eval: doc.payment_channel !== \"Phone\"",
"depends_on": "eval: doc.payment_channel == 'Email' || (!doc.payment_channel)",
"fieldname": "payment_request_message",
"fieldtype": "Section Break"
},
Expand All @@ -70,12 +70,12 @@
"fieldname": "payment_channel",
"fieldtype": "Select",
"label": "Payment Channel",
"options": "\nEmail\nPhone"
"options": "\nEmail\nPhone\nOther"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-03-27 13:10:09.836254",
"modified": "2024-03-29 18:53:09.836254",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Gateway Account",
Expand All @@ -97,4 +97,4 @@
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
}
12 changes: 6 additions & 6 deletions erpnext/accounts/doctype/payment_request/payment_request.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
"label": "Recipient Message And Payment Details"
},
{
"depends_on": "eval: doc.payment_channel != \"Phone\"",
"depends_on": "eval: doc.payment_channel == \"Email\" || (!doc.payment_channel)",
"fieldname": "print_format",
"fieldtype": "Select",
"label": "Print Format"
Expand All @@ -272,7 +272,7 @@
"label": "To"
},
{
"depends_on": "eval: doc.payment_channel != \"Phone\"",
"depends_on": "eval: doc.payment_channel == \"Email\" || (!doc.payment_channel)",
"fieldname": "subject",
"fieldtype": "Data",
"in_global_search": 1,
Expand Down Expand Up @@ -309,18 +309,18 @@
"read_only": 1
},
{
"depends_on": "eval: doc.payment_request_type == 'Inward' || doc.payment_channel != \"Phone\"",
"depends_on": "eval: doc.payment_request_type == 'Inward' || doc.payment_channel == \"Email\" || (!doc.payment_channel)",
"fieldname": "section_break_10",
"fieldtype": "Section Break"
},
{
"depends_on": "eval: doc.payment_channel != \"Phone\"",
"depends_on": "eval: doc.payment_channel == \"Email\" || (!doc.payment_channel)",
"fieldname": "message",
"fieldtype": "Text",
"label": "Message"
},
{
"depends_on": "eval: doc.payment_channel != \"Phone\"",
"depends_on": "eval: doc.payment_channel == \"Email\" || (!doc.payment_channel)",
"fieldname": "message_examples",
"fieldtype": "HTML",
"label": "Message Examples",
Expand Down Expand Up @@ -372,7 +372,7 @@
"fieldname": "payment_channel",
"fieldtype": "Select",
"label": "Payment Channel",
"options": "\nEmail\nPhone",
"options": "\nEmail\nPhone\nOther",
"read_only": 1
},
{
Expand Down
15 changes: 7 additions & 8 deletions erpnext/accounts/doctype/payment_request/payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,13 @@ def before_submit(self):
self.status = "Requested"

if self.payment_request_type == "Inward":
send_mail = self.payment_gateway_validation() if self.payment_gateway else None
if send_mail and not (self.mute_email or self.flags.mute_email):
self.set_payment_request_url()
self.send_email()
self.make_communication_entry()

elif self.payment_channel == "Phone":
if self.payment_channel == "Phone":
self.request_phone_payment()
else:
self.set_payment_request_url()
if not (self.mute_email or self.flags.mute_email):
self.send_email()
self.make_communication_entry()

def request_phone_payment(self):
controller = _get_payment_gateway_controller(self.payment_gateway)
Expand Down Expand Up @@ -231,7 +230,7 @@ def payment_gateway_validation(self):
return False

def set_payment_request_url(self):
if self.payment_account and self.payment_channel != "Phone":
if self.payment_account and self.payment_gateway and self.payment_gateway_validation():
self.payment_url = self.get_payment_url()

def get_payment_url(self):
Expand Down
29 changes: 26 additions & 3 deletions erpnext/accounts/doctype/payment_request/test_payment_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
payment_gateways = [
{"doctype": "Payment Gateway", "gateway": "_Test Gateway"},
{"doctype": "Payment Gateway", "gateway": "_Test Gateway Phone"},
{"doctype": "Payment Gateway", "gateway": "_Test Gateway Other"},
]

payment_method = [
Expand All @@ -35,6 +36,13 @@
"payment_account": "_Test Bank USD - _TC",
"currency": "USD",
},
{
"doctype": "Payment Gateway Account",
"payment_gateway": "_Test Gateway Other",
"payment_account": "_Test Bank USD - _TC",
"payment_channel": "Other",
"currency": "USD",
},
{
"doctype": "Payment Gateway Account",
"payment_gateway": "_Test Gateway Phone",
Expand Down Expand Up @@ -111,6 +119,21 @@ def test_payment_request_linkings(self):
def test_payment_channels(self):
so = make_sales_order(currency="USD")

pr = make_payment_request(
dt="Sales Order",
dn=so.name,
payment_gateway_account="_Test Gateway Other - USD",
submit_doc=True,
return_doc=True,
)
self.assertEqual(pr.payment_channel, "Other")
self.assertEqual(pr.mute_email, True)

self.assertEqual(pr.payment_url, PAYMENT_URL)
self.assertEqual(self.send_email.call_count, 0)
self.assertEqual(self._get_payment_gateway_controller.call_count, 1)
pr.cancel()

pr = make_payment_request(
dt="Sales Order",
dn=so.name,
Expand All @@ -124,9 +147,9 @@ def test_payment_channels(self):
self.assertEqual(pr.payment_channel, "Email")
self.assertEqual(pr.mute_email, False)

self.assertIsNone(pr.payment_url)
self.assertEqual(pr.payment_url, PAYMENT_URL)
self.assertEqual(self.send_email.call_count, 0) # hence: no increment
self.assertEqual(self._get_payment_gateway_controller.call_count, 1)
self.assertEqual(self._get_payment_gateway_controller.call_count, 2)
pr.cancel()

pr = make_payment_request(
Expand Down Expand Up @@ -180,7 +203,7 @@ def test_payment_channels(self):
self.assertEqual(pr.payment_channel, "Email")
self.assertEqual(pr.mute_email, True)

self.assertIsNone(pr.payment_url)
self.assertEqual(pr.payment_url, PAYMENT_URL)
self.assertEqual(self.send_email.call_count, 1) # no increment on shopping cart
self.assertEqual(self._get_payment_gateway_controller.call_count, 5)
pr.cancel()
Expand Down

0 comments on commit 79a46ad

Please sign in to comment.