I am trying to initiate a flow from the shell, with this
flow start LoanIssueFlow$InitiatorFlow owner: "O=PartyA,L=London,C=GB", supplier: "O=Notary,L=London,C=GB", bank: "O=Notary,L=London,C=GB", amount: Currencies.POUNDS(4), by: new Date(), penalty: 4, paid: Currencies.POUNDS(0)
And the flow constructor is as follow:
public InitiatorFlow(Party owner, Party supplier, Party bank, Amount<Currency> amount, Date by, double penalty, Amount<Currency> paid) {
this.state = new LoanState(owner, supplier, bank, amount, by, penalty, paid);
}
i am getting this error:
No matching constructor found:
- [net.corda.core.identity.Party, net.corda.core.identity.Party, net.corda.core.identity.Party, net.corda.core.contracts.Amount<java.util.Currency>, java.util.Date, double, net.corda.core.contracts.Amount<java.util.Currency>]: Could not parse as a command: Did not recognise the currency in Currencies.POUNDS(4) or could not parse
Thank you for the help
this is the right way of initiating that flow:
flow start LoanIssueFlow$InitiatorFlow owner: "O=PartyA,L=London,C=GB", supplier: "O=Notary,L=London,C=GB", bank: "O=Notary,L=London,C=GB", amount: $100, by: 2020-01-01, penalty: 4, paid: $0
Related
I'm using Stripe to process payments. I have a platform where international Connect accounts can sell items to others through my platform.
My platform is USD. In this specific example, the Connect account is in CAD (Canada Dollar). When someone purchases an item from this CAD Connect Account, Stripe puts the money in my platform account, leaves my app fee there, and then moves the correct amount into the CAD Connect account. It converts this amount to CAD. In the stripe GUI I can find the exchange rate and amount transferred in CAD, as circled in the screenshot below. But I can't find these attributes in the API.
The only object I've seen with an exchange_rate attribute is the balance transaction. However, when I get the balance transaction for the transaction in the screenshot, I get this response object:
Request: https://api.stripe.com/v1/balance_transactions/txn_1IBNiNLLBOhef2QNqIeaNg9o
Response:
{
"id": "txn_1IBNiNLLBOhef2QNqIeaNg9o",
"object": "balance_transaction",
"amount": -7777,
"available_on": 1611619200,
"created": 1611076199,
"currency": "usd",
"description": null,
"exchange_rate": null,
"fee": 0,
"fee_details": [],
"net": -7777,
"reporting_category": "transfer",
"source": "tr_1IBNiNLLBOhef2QNcNqv3IlS",
"status": "pending",
"type": "transfer" }
The problem here is that the balance transaction object above only shows this transaction in USD: $77.77 USD came out of my platform account.
But it doesn't show the conversion rate or the amount in CAD. When this $77.00 went into the CAD Connect account, as we can see in the GUI screenshot, that $77.77 was converted to $98.02 CAD and the exchange rate was 1.26039 (USD->CAD).
How can I find this CAD amount and exchange rate through the API?
In case you need to know the currency rate before the actual transaction happens they provide the currency rates here
HOWEVER, it's only a frontend page and it requires authorization. On top of that, it's updated once every 12 hours. There is no official API that returns currency rates.
There is a small SaaS product that provides stripe currency rates as a REST API.
https://striperates.com/
The Transfer made to the connected account in this screenshot is in USD. The conversion happens after the Transfer itself. The funds are sent in USD and then in the connected account they get converted to that account's default Currency.
You want to look at the Transfer's destination_payment property which has the py_123 id for the Charge on the connected account. That Charge has a BalanceTransaction object (similar to the Transfer one you shared). That BalanceTransaction would reflect the conversion from USD to CAD and surface the exchange rate used in the exchange_rate property in that case.
In Java you can do
Stripe.apiKey = "sk_live_...";
Transfer transfer = Transfer.retrieve("tr_...");
RequestOptions requestOptions = RequestOptions.builder().setStripeAccount("acct_...").build();
Charge charge = Charge.retrieve(transfer.getDestinationPayment(), requestOptions);
BalanceTransaction balanceTransaction = BalanceTransaction.retrieve(charge.getBalanceTransaction(), requestOptions);
balanceTransaction.getExchangeRate();
balanceTransaction.getNet();
balanceTransaction.getCurrency();
Here is the way I did : I simulated a payment in a foreign currency to a US based account (so that it is presented in US$), then I retrieved the balance transaction associated, and the exchange_rate argument
async function exchangeFeesToUS(currency) {
const paymentIntent = await stripeTestUS.paymentIntents.create({
amount: 10000,
currency: currency,
payment_method_types: ['card'],
customer: "ANY_CUSTOMER_WITH_A_PAYMENT_METHOD",
payment_method: "ANY_CARD_ASSOCIATED_TO_THIS_CUSTOMER",
confirm: true
});
return await balanceTransaction(paymentIntent).then(balance => {
return balance.exchange_rate
})
}
async function balanceTransaction(paymentIntent) {
const chargeId = paymentIntent.charges.data[0].id;
const charge = await stripeTestUS.charges.retrieve(
chargeId
);
return await stripeTestUS.balanceTransactions.retrieve(
charge.balance_transaction
);
}
Now, if you want to convert to another currency than the US$, just call the aforementioned function twice :
async function exchangeFeesToCUSTOM_CURRENCY(currency) {
const rate = await exchangeFeesToUS(currency)
const rateCUSTOM_CURRENCY = await exchangeFeesToUS('your_custom_currency')
return rate / rateCUSTOM_CURRENCY
}
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
export default functions.auth.user().onCreate(saveUserToDatabase);
async function saveUserToDatabase(event) {
const Users = admin.database().ref('Users');
const authUser = event.data;
let user = await Users.child(authUser.uid).set({
createdAt: authUser.metadata.createdAt.toString(),
email: authUser.email,
facebookId: authUser.providerData[0].uid.replace('http://facebook.com/', ''),
lastSignedInAt: authUser.metadata.lastSignedInAt.toString(),
name: authUser.displayName,
photoUrl: authUser.photoURL,
});
console.log('saveUserToDatabase()');
console.log(authUser);
}
In the above code I save a user to the firebase database when they register. Now unless I use the toString method on the dates they do not save. I looked into this a little further and found that the dates don't come in as strings and that is causing some issues. (I did this with console.log and checking the firebase dashboard)
{ displayName: 'Test User',
email: 'test#example.com',
metadata:
{ createdAt: 2017-05-02T05:18:45.000Z,
lastSignedInAt: 2017-05-02T05:18:45.000Z }
}
When I use the toString method though it converts the output to:
"Tue May 02 2017 05:24:31 GMT+0000 (UTC)"
Dates are also saved in some instances in this format:
"1492213242000"
Why is there so many timestamp formats?
What is the preferred timestamp format for firebase I should be using?
How do I convert the dates into the preferred timestamp using cloud functions?
The object you're receiving in event.data is an admin.auth.UserRecord. Its interface specifies that the createdAt and lastSignedInAt timestamps should be JavaScript Date objects.
The Date type has enough issues that we try to avoid it in newer interfaces. I suspect you may be hitting some of those pain points in the inconsistent toString() serialization.
I agree with Doug that for storage, milliseconds since the epoch should be the preferred format. You should be able to get that from createdAt.value, for example.
Following the style of this Facebook app sample using Redux and Flow together, I made an action type in this manner:
type Action =
| { type: 'ADD_FILES', files: Array<{ id: number, file: File }> }
| { type: 'HANDLE_IMAGE_PUBLISHED', id: number, name: string }
| { type: 'SET_IMAGE_UPLOAD_PROGRESS', id: number, progress: number }
;
But I've found that when I try to process my actions with a reducer, Flow complains if I try to access the name or progress properties, saying "Property not found in object type".
That is, in my reducer, if I check that action.type === 'HANDLE_IMAGE_PUBLISHED' and then access action.name, Flow complains. And the same thing goes for for accessing action.progress property when action.type === 'SET_IMAGE_UPLOAD_PROGRESS'. Both these property accesses should be legit under their respective circumstances, as far as I can tell, but Flow complains.
Yet for some reason it's OK for me to access action.id anywhere, even though one of the types in my union doesn't specify an id property. I'm very confused.
Here is a live demo in the Flow REPL. What am I doing wrong?
This is simply a case of a type refinement invalidation:
https://flow.org/en/docs/lang/refinements/#toc-refinement-invalidations
Because you are using the value in a callback, Flow pessimistically assumes that you could have re-assigned action before the callback runs (it does not know that the map callback is called immediately). It also does not do the analysis to see that there is no place, in fact, that you re-assign it.
All that's needed is to pull the action out as a const:
export default (state: Array<ImageRecordModel> = [], action_: Action): Array<ImageRecordModel> => {
const action = action_;
(tryflow link)
You may also want to consider enabling const params in your .flowconfig. This does basically what you expect: treats all params as const:
[options]
experimental.const_params=true
We are implementing an auction cloud service, that will receive orders, from an external API service on demand. Each received order is a 1:1 to an auction.
We can have more than 2000 orders (auctions) per day.
we have decided to use Microservices + Redux to separate concerns between orders and auctions.
Bellow are the explanation of each service.
External API
Enternal API is just a website that pushes orders to our Order Service and receive updates from our Order service we have no control over it.
Order service
Orders has a bunch of information (properties) that the client (mobile app) use to get information to decide on joining an auction. for example, this is how an order can look like:
{
id: 123,
description: 'Some description',
salePrice: 0,
minPrice: 1000,
openPrice: 500,
status: 'active',
address: 'Some address',
file: '.../some-file.pdf',
client: 'Joe Doe',
notes: 'Some notes',
createdAt: '12345678',
pending: false,
postpone: false,
...moreproperties
}
In the order service the orders can be updated (address, name, openPrice, minPrice, status, etc) by the server at any time before the auction starts via the actions bellow.
{ type: LOAD_ORDERS, orders }
{ type: PEND_ORDER, id }
{ type: POSTPONE_ORDER, id }
{ type: SET_ORDER_AUCTION, id, auction, salePrice }
{ type: UPDATE_ORDER, id, properties }
Auction Service
An auction object in this service can look like this:
{
id: 'abcd',
orderId: 123456,
increment: 1,
outBid: { agentId: 'b1', price: 545 },
bestBid:{agentId: 'b2', price: 550 },
openPrice: 500,
currentPrice: 550,
status: 'started'
startedByAgent: 'a1'
}
Auctions can be updated by these actions:
{ type: JOIN_AUCTION, id, agentId, type }
{ type: START_AUCTION, id, agentId }
{ type: PLACE_BID, id, agentId, price }
{ type: END_AUCTION, id, agentId }
API Service
It works just as gateway between front end app and the microservices. Receive and dispatch requests from clients (mobiles) to Order Service or Auction Service in form of actions.
Workflow:
1 - External API push orders of the day to Order Service via LOAD_ORDERS also a CREATE_AUCTIONS action is dispatched to the Action Service to create an auction for each order.
2 - User open mobile app and get the list of orders of the day with details including open prices from Order Service.
3 - User join an specific order
- API Service creates a bidder agent that will place bids.
- API Service send a join action via JOIN_AUCTION to join an auction on the Auction Service
4 - An auctioneer agent starts the auction and bidding starts.
5 - Joined bidder agents starts to place bids via PLACE_BID action on Auction Service.
6 - When auction is over the auctioneer agent ends the auction by dispatching END_AUCTION.
7 - When auction ends sale price and auction details (via object) are send to the Order Service via the SET_ORDER_AUCTION.
8 - The Order Service handle the SET_ORDER_AUCTION and update the order state with the final salePrice and the auction object and then wait for payment.
9 - Once payment info is received from the client then it is submitted to the External Service by Order Service
My questions are:
Is the workflow above a reasonable approach for using Microservices + Redux and updating each service state?
It is ok to dispatch actions from a microservice to another when using redux microservices? My question is because when using microservices + event sourcing + CQRS, services intercommunication are not recommended but instead using a Sagas that work as intermediate service that convert events to commands.
My other question is where to put business logic (validation), for example a bidder cannot send bid if auction is not started or its already ended, a bidder cannot send a bid if he/she has not joined the auction yet. Were to put this logic? in action, middleware or reducers? and how to handle errors back to clients?
In general what are some best practices when it comes to Microservices + Redux?
What are pros and cons of using Microservices + Redux vs Microservices + Event sourcing + CQRS?
Sorry for the long post, I just need some orientation here because I cannot find any documentation about this topic and I am not sure if I am approaching this right.
Any advice would be appreciated!!!
I think this questions is way off the guidelines.
Nevertheless, I'd say write your own redux middleware to integrate your microservices; the API is very simple:
store => next => action => {
let result = next(action)
return result
}
In the most outer function (store =>) you can add microservice listerner and dispatch actions via the store reference.
In the innermost function (action =>) you can react to actions in the redux app by sending requests to your microservices.
I've setup the Gracenote SDK for iOs and successfully made some videos lookup.
I've noticed that for series the sdk correctly return the episode number but don't return season number and for many series.
Here are the logs (Big Bang Theory)
airing start: 2015-10-03T10:05
airing end: 2015-10-03T10:30
channel tui: 251537434
channel tag: F65C41B31CA03052BAD934B93C9ACF57
channel name: NRJ 12
channel callsign: NRJ 12
channel number:
program tui: 556745075
program tag: 63D1515CDA5AD50A6579997F97598833
program title: The Big Bang Theory
program subtitle: La démission de Penny
program seasonNumber: 0
program episode: 13
for:
NSLog(#"program tui: %#", program.tui);
NSLog(#"program tag: %#", program.tuiTag);
NSLog(#"program title: %#", program.officialTitle.display);
NSLog(#"program subtitle: %#", program.subtitle.display);
NSLog(#"program seasonNumber: %lu", (unsigned long)program.seasonNumber);
NSLog(#"program episode: %lu", (unsigned long)program.seasonEpisodeNumber);
Did I missed something ?
You are doing it right. The season data does not exist for this series in your region. A workaround I can think of is do a follow up query using OnConnect API to get the season number.
Here is how: use the program subtitle you received as the query string, specify entityType as "episode" and descriptionLang to your language ("fr" in your case), and make a Program Search method call. Below is the query, FYI.
http://data.tmsapi.com/v1.1/programs/search?q=La+d%C3%A9mission+de+Penny&entityType=episode&descriptionLang=fr&api_key=YOUR_ONCONNECT_API_KEY
About OnConnect API, please visit http://developer.tmsapi.com for more details.
There may be another workaround using another Gracenote API. I will do some research and update this answer.