Skip to content

(Online shop) u2u payment processing, change to “3-wallet with queuing” approach #283

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

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from

Conversation

adisa39
Copy link
Collaborator

@adisa39 adisa39 commented Jul 5, 2025

Included a2uPaymentQueue schema to store A2U payment and track payment status.
Included gas saver logics that batch revenue for each seller on the a2uPaymentQueue collection.
Added function to enqueue payment.
implement cron-job to automate A2U payments at 5minutes intervals.

Copy link

vercel bot commented Jul 5, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
map-of-pi-backend-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2025 5:16pm

@swoocn
Copy link
Member

swoocn commented Jul 5, 2025

Hi @adisa39 - I'm sure you're already aware, but It looks like the build is currently failing due to some unit tests that weren’t updated to reflect your recent changes. I will go ahead and resolve them.

Copy link
Member

Choose a reason for hiding this comment

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

I’ll work on tidying up the cron job setup so both your A2U process and the Sanction bot can run in parallel.

Copy link
Collaborator Author

@adisa39 adisa39 Jul 6, 2025

Choose a reason for hiding this comment

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

Oh! That will be nice, thanks.

I don’t know we are still using the cron job for sanction regions implementation, they sections were all commented out before I started working on it.


// workers/mongodbA2UWorker.ts
async function processNextJob(): Promise<void> {
const now = new Date();
Copy link
Member

Choose a reason for hiding this comment

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

Declared but not used.


if (!job) return;

const { sellerPiUid, amount, xRef_ids, _id, attempts, memo, last_a2u_date } = job;
Copy link
Member

Choose a reason for hiding this comment

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

memo and last_a2u_date is not being used.

Copy link
Collaborator Author

@adisa39 adisa39 Jul 6, 2025

Choose a reason for hiding this comment

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

Though it can be considered in the enqueue function, it’s is not used because of the payment batching for gas saver, that is multiple payment from different buyers with different memo descriptions.

import mongoose, { Schema } from "mongoose";
import { IA2UJob } from "../types";

const A2UPaymentQueueSchema = new Schema<IA2UJob>(
Copy link
Member

@swoocn swoocn Jul 6, 2025

Choose a reason for hiding this comment

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

Hi @adisa39 - I noticed that this DB schema doesn’t align with the PaymentQueue model outlined in the schema documentation @ https://docs.google.com/document/d/1i9JjD3veU4RmZXEiD_D9j7XvRIcZm9koJ_DFDITe1H0/edit?usp=sharing

It would have been helpful to get your feedback during the schema design phase or possibly during implementation. Just checking — was there a reason you disagreed with the proposed model, or was this an oversight? Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @swoocn - please note that various approaches have been tried before arriving at this implementation. So my thought is to raised this once execution is done and solid.

The proposed model has some repeated fields that can be accessed from other collections using foreign keys. More importantly batching of payments from different buyers with different payment details (payer_pi_username, u2a_blockchain_id, description etc.) cannot go with this feature implementation.

Please let me know your thoughts on this.
Thanks.

Copy link
Member

Choose a reason for hiding this comment

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

Understood; no problem @adisa39!
I will make a note of this in the card and adjust the DB collection schema accordingly. 👍

enum: ['pending', 'processing', 'completed', 'failed', 'batching'],
default: 'pending',
},
last_a2u_date: { type: Date, default: null },
Copy link
Member

Choose a reason for hiding this comment

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

Hi @adisa39 - could you clarify the difference between the last_a2u_date timestamp and the updatedAt timestamp in the context of A2U queue payment processing? Thanks, in advance!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The last_a2u_date is used in the payment batching to determine the date of the next A2U payment for sellers with their gas saver turned on (3days from last payout). While the updatedAt keeps tracks of payment status changes while determining its position on the queue.

Copy link
Member

@swoocn swoocn Jul 7, 2025

Choose a reason for hiding this comment

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

Then perhaps it would make sense to rename the field to something like last_batched_a2u_date or last-gas-saver-a2u-date? Thoughts?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not necessary, since it’s applicable to all records and sellers with their gas saver turned off can also turned it on

Copy link
Member

Choose a reason for hiding this comment

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

What about last_a2u_payout_date @adisa39?

default: 'pending',
},
last_a2u_date: { type: Date, default: null },
attempts: { type: Number, default: 0 },
Copy link
Member

Choose a reason for hiding this comment

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

Could we change the attempts field to num_retries as per the DB schema document?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes

Copy link
Member

Choose a reason for hiding this comment

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

Scripts are located in the /scripts folder, which is currently hidden and excluded from commits for security reasons. These scripts are intended to be shared among developers and maintained locally, rather than being stored in the repository.

const A2UPaymentQueueSchema = new Schema<IA2UJob>(
{
sellerPiUid: { type: String, required: true },
amount: { type: Number, required: true },
Copy link
Member

@swoocn swoocn Jul 9, 2025

Choose a reason for hiding this comment

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

Shouldn't amount field be Types.Decimal128 to maintain data type consistency?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This type usually difficult to handle in the BE/FE logics

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha! I can see how that may be the case. Let's stick to just Number for now then.

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

Successfully merging this pull request may close these issues.

2 participants