@@ -23,6 +23,8 @@ export const prepareRequestParameters = ({
2323 amountInUSD,
2424 createdWith,
2525 builderId,
26+ productName,
27+ sellerName,
2628} : {
2729 currency : Currency ;
2830 sellerAddress : string ;
@@ -32,20 +34,22 @@ export const prepareRequestParameters = ({
3234 amountInUSD : number ;
3335 builderId : string ;
3436 createdWith : string ;
37+ productName : string | undefined ;
38+ sellerName : string | undefined ;
3539} ) => {
3640 const isERC20 = currency . type === Types . RequestLogic . CURRENCY . ERC20 ;
3741 const currencyValue = isERC20 ? currency . address : "eth" ;
38-
42+ const amount = utils
43+ . parseUnits ( amountInCrypto . toFixed ( currency . decimals ) , currency . decimals )
44+ . toString ( ) ;
3945 return {
4046 requestInfo : {
4147 currency : {
4248 type : currency . type ,
4349 value : currencyValue ,
4450 network : currency . network ,
4551 } ,
46- expectedAmount : utils
47- . parseUnits ( amountInCrypto . toString ( ) , currency . decimals )
48- . toString ( ) ,
52+ expectedAmount : amount ,
4953 payee : {
5054 type : Types . Identity . TYPE . ETHEREUM_ADDRESS ,
5155 value : sellerAddress ,
@@ -69,15 +73,44 @@ export const prepareRequestParameters = ({
6973 } ,
7074 } ,
7175 contentData : {
72- paymentCurrency : {
73- type : currency . type ,
74- value : currencyValue ,
75- network : currency . network ,
76+ meta : {
77+ format : "rnf_invoice" ,
78+ version : "0.0.3" ,
79+ } ,
80+ creationDate : new Date ( ) . toISOString ( ) ,
81+ invoiceNumber : "rn-checkout" ,
82+ note : `Sale made with ${ currency . symbol } on ${ currency . network } for amount of ${ amountInUSD } USD with an exchange rate of ${ exchangeRate } ` ,
83+ invoiceItems : [
84+ {
85+ name : productName || "" ,
86+ quantity : 1 ,
87+ unitPrice : amount ,
88+ discount : "0" ,
89+ tax : {
90+ type : "percentage" ,
91+ amount : "0" ,
92+ } ,
93+ currency : currencyValue ,
94+ } ,
95+ ] ,
96+
97+ paymentTerms : {
98+ dueDate : new Date ( ) . toISOString ( ) ,
99+ } ,
100+ sellerInfo : {
101+ businessName : sellerName || undefined ,
102+ } ,
103+ miscellaneous : {
104+ exchangeRate : exchangeRate . toString ( ) ,
105+ amountInUSD : amountInUSD . toString ( ) ,
106+ createdWith,
107+ builderId,
108+ paymentCurrency : {
109+ type : currency . type ,
110+ value : currencyValue ,
111+ network : currency . network ,
112+ } ,
76113 } ,
77- exchangeRate : exchangeRate . toString ( ) ,
78- amountInUSD : amountInUSD . toString ( ) ,
79- createdWith,
80- builderId,
81114 } ,
82115 signer : {
83116 type : Types . Identity . TYPE . ETHEREUM_ADDRESS ,
@@ -164,7 +197,7 @@ export const handleRequestPayment = async ({
164197 await inMemoryRequestNetwork . createRequest ( requestParameters ) ;
165198
166199 const signer = await ethersProvider ! . getSigner ( ) ;
167- const confirmationBlocks = getConfirmations ( targetChain ! . chainId ) ;
200+ const confirmationBlocks = 1 ;
168201 if ( isERC20 ) {
169202 const requestData = inMemoryRequest . inMemoryInfo ?. requestData ! ;
170203
@@ -217,25 +250,26 @@ export const handleRequestPayment = async ({
217250
218251function getChainFromNetwork ( network : string ) : ( typeof chains ) [ 0 ] | undefined {
219252 const networkLower = network . toLowerCase ( ) ;
220- return chains . find (
221- ( chain ) =>
222- chain . name . toLowerCase ( ) === networkLower ||
223- chain . currency . toLowerCase ( ) === networkLower
224- ) ;
225- }
226-
227- const getConfirmations = ( chainId : number ) : number => {
228- switch ( chainId ) {
229- case 137 : // Polygon
230- return 15 ;
231- case 56 : // Binance Smart Chain
232- case 43114 : // Avalanche
233- case 250 : // Fantom
234- return 5 ;
253+ switch ( networkLower ) {
254+ case "mainnet" :
255+ case "ethereum" :
256+ return chains . find ( ( chain ) => chain . name . toLowerCase ( ) === "ethereum" ) ;
257+ case "bsc" :
258+ case "binance smart chain" :
259+ return chains . find (
260+ ( chain ) => chain . name . toLowerCase ( ) === "binance smart chain"
261+ ) ;
262+ case "zksyncera" :
263+ case "zksync era" :
264+ return chains . find ( ( chain ) => chain . name . toLowerCase ( ) === "zksync era" ) ;
235265 default :
236- return 2 ;
266+ return chains . find (
267+ ( chain ) =>
268+ chain . name . toLowerCase ( ) === networkLower ||
269+ chain . currency . toLowerCase ( ) === networkLower
270+ ) ;
237271 }
238- } ;
272+ }
239273
240274function getNetworkParams ( chain : ( typeof chains ) [ 0 ] ) : any {
241275 return {
0 commit comments