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

fix(background)!: better payment confirmation & message #694

Merged
merged 36 commits into from
Nov 27, 2024

Conversation

sidvishnoi
Copy link
Member

@sidvishnoi sidvishnoi commented Nov 1, 2024

Context

Changes proposed in this pull request

  • Poll for outgoing payment.
    • We poll every 1.5s for up to total 8s, with initial delay also of 1.5s.
    • Polling success is defined as sentAmount == debitAmount.
    • We keep emitting latest OutgoingPayment state, so even if polling isn't success, we may have partial payment.
    • Error state corresponds to: OutgoingPayment.failed = true and sentAmount == 0
    • Payment warning corresponds to: polling timeout reached and sentAmount is still zero.
    • We start polling immediately, as part of pay({ amount })
    • I'm not sure if it'll be better to inform user of these two parts, as polling can show the spinner for up to additional 8s. We might want to show user two parts to avoid showing infinite spinner: "Sending..." ... "Verifying payment"?
    • Added read permission on outgoing-payment (breaking change as calls from existing connected extensions will throw on read), but avoided breaking change by catching the error and checking debitAmount from initial outgoing payment response like before.
  • Update UI to show error/warning/success message; remove "Payment successful" button state.

@github-actions github-actions bot added area: background Improvements or additions to extension background script area: i18n labels Nov 1, 2024
Copy link
Contributor

github-actions bot commented Nov 1, 2024

Extension builds preview

Name Link
Latest commit 5347047
Latest job logs Run #12048527869
BadgeDownload
BadgeDownload

In case we decide to do the polling separately, we don't need to store
entire initial outgoingPayment for reference.
[ci skip]
@github-actions github-actions bot added the area: popup Improvements or additions to extension popup label Nov 8, 2024
@sidvishnoi sidvishnoi changed the title fix(background)!: better payment confirmation message fix(background)!: better payment confirmation & message Nov 8, 2024
@sidvishnoi sidvishnoi marked this pull request as ready for review November 8, 2024 09:48
@sidvishnoi
Copy link
Member Author

src/background/config.ts Outdated Show resolved Hide resolved
src/background/services/monetization.ts Show resolved Hide resolved
src/_locales/en/messages.json Outdated Show resolved Hide resolved
Comment on lines 57 to 59
"pay_error_outgoingPaymentFailed": {
"message": "We were unable to process this transaction. Please try again!",
"description": "OutgoingPayment.failed === true"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed should happen when outgoing_payment.failed = false and outgoing_payment.sent_amount === 0, since the OP can fail during sending and only send a partial amount.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, OutgoingPayment.failed = true and OutgoingPayment.sent_amount > 0 is possible?

We want to treat any partial amount to be treated as success here?

Copy link
Member

@raducristianpopa raducristianpopa Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, OutgoingPayment.failed = true and OutgoingPayment.sent_amount > 0 is possible?

Yes.

We want to treat any partial amount to be treated as success here?

We cannot treat a sent partial amount as an error (failed = true && sent_amount = 0), since an amount was actually sent. We can use payStatus.type = 'partial' for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed cases with @raducristianpopa on Slack. We need to handle these cases:

failed = T; sent_amount = 0             => definitely error. immediate fail.
failed = F; sent_amount = 0             => we don't know yet. maybe warn user? It could be an error if check for long enough, or sent_amount might become non-zero

failed = T; sent_amount > 0             => ok, but only a partial was sent
failed = F; sent_amount > 0             => ok, but only a partial was sent, can be successfully completed afterwards

failed = T; sent_amount = debit_amount  => not possible
failed = F; sent_amount = debit_amount  => ok. immediate success.

@RabebOthmani How to best show this to user? For added context, after the payment, we've to repeatedly check payment status (polling). Right now, we check for up to 8 seconds only. The payment might be in any of above 5 states.

Also, note that, we'll be showing user a spinner for those 8s. Might be better to show "verifying payment status" message while we are in verify stage?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8s is a long time for just a spinner. My unsolicited opinion is that we should show some kind of messaging for sure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per Slack:

  • " It looks like this is taking long. Check your wallet later to ensure the payment went through"
  • Partial payment- only was successfully sent. to learn more

src/background/services/openPayments.ts Outdated Show resolved Hide resolved
src/popup/components/PayWebsiteForm.tsx Outdated Show resolved Hide resolved
src/background/services/monetization.ts Show resolved Hide resolved
src/background/services/monetization.ts Outdated Show resolved Hide resolved
src/background/services/openPayments.ts Outdated Show resolved Hide resolved
src/popup/components/PayWebsiteForm.tsx Outdated Show resolved Hide resolved
Copy link
Member

@raducristianpopa raducristianpopa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not have a message for a partial payment?

Comment on lines +923 to +926
const token = await this.rotateToken();
const hasReadAccess = token.access_token.access.find(
(e) => e.type === 'outgoing-payment' && e.actions.includes('read'),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Lets just add a comment, that this specific part can be removed once we have the RS errors in place.

@sidvishnoi
Copy link
Member Author

We do not have a message for a partial payment?

Yep, we treat it as regular payment, and as success (pay_state_success key). Not sure if showing partial amount in message is a good idea though - might confuse users.

@RabebOthmani
Copy link
Collaborator

@sidvishnoi all good on here ? Do you need more input from me?

@sidvishnoi
Copy link
Member Author

@RabebOthmani Two points actually (can be addressed as follow-up I guess, as this PR is pending since too long)

(1)

Also, note that, we'll be showing user a spinner for those 8s. Might be better to show "verifying payment status" message while we are in verify stage? #694 (comment)

8s is a long time for just a spinner. My unsolicited opinion is that we should show some kind of messaging for sure. #694 (comment)

(2)

We do not have a message for a partial payment? #694 (review)

Yep, we treat it as regular payment, and as success (pay_state_success key). Not sure if showing partial amount in message is a good idea though - might confuse users. #694 (comment)

@sidvishnoi sidvishnoi merged commit 2e7aa96 into main Nov 27, 2024
9 checks passed
@sidvishnoi sidvishnoi deleted the payment-confirmation branch November 27, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: background Improvements or additions to extension background script area: i18n area: popup Improvements or additions to extension popup
Projects
None yet
4 participants