Skip to content
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: log payment info to activity log in reference document #63

Open
batonac opened this issue Jan 5, 2024 · 0 comments
Open

feat: log payment info to activity log in reference document #63

batonac opened this issue Jan 5, 2024 · 0 comments

Comments

@batonac
Copy link
Contributor

batonac commented Jan 5, 2024

It would enhance the administrative experience tremendously to create a better paper trail between payments and associated documents if the payment details were linked to the activity log on the reference document.

For example, on the stripe integration (stripe_settings.py), the following would do the trick:

    def create_charge_on_stripe(self):
        import stripe

        try:
            charge = stripe.Charge.create(
                amount=cint(flt(self.data.amount) * 100),
                currency=self.data.currency,
                source=self.data.stripe_token_id,
                description=self.data.description,
                receipt_email=self.data.payer_email,
            )

            if charge.captured == True:
                self.integration_request.db_set(
                    "status", "Completed", update_modified=False
                )
                self.flags.status_changed_to = "Completed"

                # log the payment URL and receipt URL to the document
                payment_amount = frappe.utils.fmt_money(
                    charge.amount / 100, currency=charge.currency
                )
                payment_url = "https://dashboard.stripe.com/payments/" + charge.id
                receipt_url = charge.receipt_url
                comment = (
                    f"<strong>Payment of {payment_amount} received via Stripe</strong><br>"
                    f"<a target='_blank' rel='noopener noreferrer' href='{payment_url}'>View the Payment</a><br>"
                    f"<a target='_blank' rel='noopener noreferrer' href='{receipt_url}'>View the Receipt</a>"
                )
                doc = frappe.get_doc(
                    self.data.reference_doctype, self.data.reference_docname
                )
                doc.add_comment("Info", comment)

            else:
                frappe.log_error(charge.failure_message, "Stripe Payment not completed")

        except Exception:
            frappe.log_error(frappe.get_traceback())

        return self.finalize_request()

As you can see, this change:

  1. Extends the if charge.captured == True: conditional action in the create_charge_on_stripe function.
  2. Evaluates the gateway-specific payment url and receipt url.
  3. Combines the payment_amount and links into a comment text.
  4. Saves the comment as type "Info" on the reference document.
  5. The result is that a comment is logged in the activity feed on the document, as follows:
    image

I suggest that this approach should be extended to all gateways so it could be incorporated into the app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant