By usecases 1.create customer 2.update(kyc) 3.Deposit 4 Fund transfer using 3 microservices Api validation - microservices

USE case :
Create customer
create a table with name customers having following columns : Id(Numeric), customer_id(varchar), customer_name(varchar), customer_mobileNo(Numeric), EmailId(Varchar) Account_Id(varchar), Amount(Numeric), address(varchar), is_KYC_DONE(Boolean), active(Boolean)
Make a post rest end point to insert data into the customer table and register 2 customers with default amount like 0.
API Validation be like customer_id, customer_name, account_id should be mandatory, Mobile number should be numeric, Email should be in right format, is_KYC_DONE and active should have default value of 0 and 1
Update KYC to true
Make a patch rest point to update kyc in table to true on basis of customer id.
Deposit
Make a post rest end point to deposit amount in above created table based on account id
Deposit should happen when kyc is done i.e true otherwise tranaction will be declined
Fund transfer
Make a post rest point to do amount transfer from one account to another.
payload should be like this :
transfer {
“Amount” :
withdraw {
“Account_id” : “”
},
Deposit {
“Account_id” : “”
}
}
Validation be like
Sufficent funds should be dere
for both withdraw and deposit accountId and amount should be mandatory.
if deposit fails then amount withdrawn from account should be rollbacked.
NOTE : Mke sure atmost once and at least once the transaction should happen.
There will 3 microservices
customer : will have create customer and update kyc end points
Deposit : will have deposit end point
fundtransfer : will have fundtransfer endpoint, withdraw happens from this microservice and for deposit call should go to deposit miroservice.
I am in the process of learning about microservices and there's one thing that I can't seem to figure out and I can't find any resources that give me a direct answer to this. The question is: Do microservices involve only business logic and

Related

Convert column value from null to value of similar row with similar values

sorry for the slightly strange Title I couldn't think of a succinct way to describe my problem.
I have a set of data that is created by one person, the data is structured as follows
ClientID ShortName WarehouseZone RevenueStream Name Budget Period
This data is manually inputted, but as there are many Clients and Many RevenueStreams only lines where budget != 0 have been included.
This needs to connect to another data set to generate revenue and there are times when revenue exists, but no budget exists.
For this reason I have gathered all customers and cross joined them to all codes and then appended these values into the main query, however as warehousezone is mnaually inputted there are a lot of entries where WarehouseZone is null.
This will always be the same for every instance of the customer.
Now after my convuluted explanation there's my question, how can I
-Psuedo Code that I hope makes sense.
SET WarehouseZone = WarehouseZone WHERE ClientID = ClientID AND
WarehouseZone != NULL
Are you sure that a client has one WarehouseZone? otherwise you need a aggregation.
Let's check, you can add a custom column that will return a record like this:
Table.Max(
Table.SelectColumns(
Table.SelectRows(#"Last Step" ,
each [ClientID] = _[ClientID])
, "Warehousezone")
,"Warehousezone"
)
This may create a new column that will bring the max warehousezone of a clientid everytime. At the end you can expand the record to get the value.
P/D The calculation is not so good for performance

Fetch first charge of a customer in stripe

I am reading stripe documentation and I want to fetch the first charge of the a customer. Currently I am doing
charge_list = Stripe::Charge.list(
{
customer: "cus_xxx"
},
"sk_test_xxxxxx"
)
first_charge = charge_list.data.last
Since stripe api returns the charges list in sorted order with the most recent charges appearing first. But I don't think it is a good approach. Can anyone help me with how can I fetch the first charge by a customer or how can I sort the list with descending order of created date so that I could get the first object from the array.
It seems there is no reverse order sorting feature in stripe API.
Also remember the first charge may not be on the first page result set, so you have to iterate using #auto_paging_each.
A quick possible solution:
charge_list = Stripe::Charge.list(
{customer: "cus_xxx", limit: 100 }, # limit 100 to reduce request
"sk_test_xxxxxx")
first_charge = nil
charge_list.auto_paging_each {|c| first_charge = c }
You may want to persist the result somewhere since it is a heavy operation.
But the cleanest solution IMO would be to store all charge records into your DB and make subsequent queries against it.

Laravel cashier + Stripe : creating a plan with quantity and decreasing prices

I'm whiling for one of my project to create a subscription system with Laravel Cashier and Stripe.
We will offer one plan to our users : 10€ / month for one location (they can add locations in the system) and for 75 followers.
What I want to do, is to make them pay more for locations : 2.5€ / locations / month for example, so this can be achieve with quantities ? But still, if the basic plan is at 10€ and I put 2 as a quantity, total price will be 20€ ?
Then price will be also based on their followers. 75 are included in the basic price. But then if they want more, they will also have to pay.
Example :
76-150 : + 4.95€ a month
151-250 : + 4.80€ a month etc ...
How can I handle that and make sure the customer will have to pay everything in one shot ?
Thanks in advance !
My advice would be to;
Calculate the total charge in your own logic,
Initiate a 'once-off' payment by first creating a customer object,
Then creating a charge!
Easy as 1,2,3 :D
Here's a tutorial from Stripes documentation on creating payments.
https://stripe.com/docs/charges
If you would like to add the user to a plan (subscription), see the below example (in PHP).
$customer = \Stripe\Customer::create(array(
"source" => $tokenID,
"plan" => $plan,
"email" => $email,
"coupon" => $coupon
));
I would use my front or back end to calculate:
price
discount rate
When the calculation is done, you can create your subscription with the right quantity and price, and discount rate (discount coupon).
$user->newSubscription('main', 'main')
->quantity($quantity)
->withCoupon($coupon)
->create($token, ['email' => $user->email]);

Stripe Subscription Plans of Varying Amounts

I am working on a donation form for a charity and they have requested a monthly donation plan where the user can choose whatever amount they would like to give.
I know I can make individual plans (i.e. if they said monthly donations of $5, $10, or $20 dollars) I could make three different plans and subscribe users to them. Is there a way to avoid making new plans for every varying subscription amount?
The Stripe documentation recommends using the quantity parameter on the subscription.
https://stripe.com/docs/guides/subscriptions
Varying billing amounts
Some users need full flexibility in computing billing amounts. For
example, you might have a conceptual subscription that has a base cost
of $10 per month, and a $5 per-seat cost each month. We recommend
representing these billing relationships by creating a base plan that
is only $1 per month, or even $0.01 per month. This lets you use
quantity parameter to bill each user very flexibly. In an example
with a $10 base cost and three $5 seats, you could use a $1 per month
base plan, and set quantity=25 to achieve the desired total cost of
$25 for the month.
I don't think you can do it with Stripe.
What you can do is keep using Stripe and dynamically build the subscription plans using Stripe API or move to PayPal and use their Preapproval operation.
https://developer.paypal.com/docs/classic/api/adaptive-payments/Preapproval_API_Operation/
Your question seems self-defeating -- you can't have subscriptions of varying amounts without creating the corresponding plans!
The simplest way to handle recurring donations of varying amounts would be to create one plan per donator. For instance, you could do something like this:
# Create the plan for this donator
plan = Stripe::Plan.create(
:amount => params[:amount],
:currency => 'usd',
:interval => 'month',
:name => 'Donation plan for #{params[:stripeEmail]}',
:id => 'plan_#{params[:stripeEmail]}'
)
# Create the customer object and immediately subscribe them to the plan
customer = Stripe::Customer.create(
:source => params[:stripeToken],
:email => params[:stripeEmail],
:plan => plan.id
)
If you wish to avoid creating unnecessary plans, you could simply check if an appropriate plan already exists. The simplest way to do so would be to use a naming convention that includes the amount. For instance:
plan_id = '#{params[:amount]}_monthly'
begin
# Try to retrieve the plan for this amount, if one already exists
plan = Stripe::Plan.retrieve(plan_id)
rescue Stripe:: InvalidRequestError => e
# No plan found for this amount: create the plan
plan = Stripe::Plan.create(
:amount => params[:amount],
:currency => 'usd',
:interval => 'month',
:name => "$#{'%.02f' % (params[:amount] / 100.0)} / month donation plan",
:id => plan_id
)
# Create the customer object as in the previous example
(Note that in both these examples, I assumed that params[:amount] would be the donation's amount, as an integer in cents.)

Account Balance For Invoice Purposes Access 2010

I have created a new transactions table (tblTransactions) where I can log all my [Debits] (i.e. invoices) and [Credits] (i.e.payments). From this I can run a query with an an expression to get the Current Account Balance.
However, for invoicing purposes, if I pulled the Current Account Balance as described above, it wouldn't be the 'previous account balance' value I want to display to the customer on the invoice, because it's showing a value which includes the current invoice amount. I want the customer to see the previous balance PRIOR TO that invoice.
My current solution uses expressions in a query to calculate this 'previous account balance', but I don't know if could be done another way. Any suggestions on how this could be done better?
I couldn't post a picture of the query b/c I don't have enough reputation points.
Invoice fields I'm trying to populate:
Invoice Amount
Previous Account Balance (prior to this invoice)
Final Invoice Amount
Below are my calculations used in the query
Invoice Amount: Debit
Previous Account Balance: Format([Account Credits]-[Account Debits],"Currency")
Final Invoice Amount: Format([Invoice Amount]-[Previous Account Balance],"Currency")
Account Debits: Format(DSum("[Debit]","tblTransactions","ClientID =" & [ClientID])-[Debit],"Currency")
*This formula takes out the value of the current debit in the query
Account Credits: Format(DSum("[Credit]","tblTransactions","ClientID =" & [ClientID]),"Currency")
A solution "quick and dirty" is to find add a condition to your query excluding the record on which you are working (current invoice).
If you have an ID, you can add a WHERE condition to your DSUM, excluding the current record.
Let's assume IDTransact is ID field of tblTransactions, your WHERE condition should be
"ClientID =" & [ClientID] & "AND IDTransact <> " & CStr([IDTransact])
I assumed the ID is a long (autonumbering).
Hope this can help you.
Let me know.
Bye

Resources