Skip to content

Commit fbe9899

Browse files
authored
forte payment (#405)
* added fetchForteAccessToken and createPaymentIntent endpoint * add usePaymentIntent flow * forte config * openSea testnet * forte integration opensea * payment status checking * pass selleraddress to payment intent * widget data * changed test input for opensea tx * fixed widget data * return null from the widget loader * response.ok check * fix for forte widget implementation * Forte payment controller (WIP) * initialize fortepayment from the controller * forte orderHash * different types for different payment configs * added magic eden payment intent * linter fixes * mint configs for forte * updated forte info for mints * calldata fix * added config for custom evm call * forte contract address * forte settings * payment modal presets * orderbook transaction data * config update * removal of magic eden for forte * structure call data for forte paymetns * orderbook integration * fixed onSuccess params * fixed forte flow not starting * added approvedspender field * styles * added settings for checkout * fixes related to approvedSpender address * fixes to configuration * fixed body to work with sequence api * integration with sequence backend for forte * clean up * prevent onSuccess callback from being called multiple times * improve error messages * custom_evm_call fixes * added seller as targetContracts for mints * used seller from forteconfig * fixed the apiUrl * pass project access key to forte endpoints * updated dev access key * updated project access key for dev environmnet * fix linter errors * removed dedicated seaport forteconfig option * wait for FortePaymentsWidgetLoaded even before opening the modal * checkout in demo defaults to forte
1 parent 72046b6 commit fbe9899

File tree

24 files changed

+1433
-263
lines changed

24 files changed

+1433
-263
lines changed

examples/react/src/components/Connected.tsx

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import {
44
useCheckoutModal,
55
useERC1155SaleContractCheckout,
66
useSelectPaymentModal,
7-
useSwapModal
7+
useSwapModal,
8+
type SwapModalSettings
89
} from '@0xsequence/checkout'
9-
import type { SwapModalSettings } from '@0xsequence/checkout'
1010
import {
1111
getModalPositionCss,
1212
signEthAuthProof,
@@ -23,16 +23,15 @@ import { useOpenWalletModal } from '@0xsequence/wallet-widget'
2323
import { CardButton, Header, WalletListItem } from 'example-shared-components'
2424
import { AnimatePresence } from 'motion/react'
2525
import React, { useEffect, type ComponentProps } from 'react'
26-
import { encodeFunctionData, formatUnits, parseAbi, toHex, zeroAddress } from 'viem'
26+
import { encodeFunctionData, formatUnits, parseAbi } from 'viem'
2727
import { createSiweMessage, generateSiweNonce } from 'viem/siwe'
2828
import { useAccount, useChainId, usePublicClient, useSendTransaction, useWalletClient, useWriteContract } from 'wagmi'
2929

3030
import { sponsoredContractAddresses } from '../config'
3131
import { messageToSign } from '../constants'
32-
import { ERC_1155_SALE_CONTRACT } from '../constants/erc1155-sale-contract'
33-
// import { ERC_721_SALE_CONTRACT } from '../constants/erc721-sale-contract'
3432
import { abi } from '../constants/nft-abi'
3533
import { delay, getCheckoutSettings, getOrderbookCalldata } from '../utils'
34+
import { checkoutPresets } from '../utils/checkout'
3635

3736
import { CustomCheckout } from './CustomCheckout'
3837
import { Select } from './Select'
@@ -42,6 +41,7 @@ const searchParams = new URLSearchParams(location.search)
4241
const isDebugMode = searchParams.has('debug')
4342
const checkoutProvider = searchParams.get('checkoutProvider')
4443
const onRampProvider = searchParams.get('onRampProvider')
44+
const checkoutPreset = searchParams.get('checkoutPreset') || 'forte-payment-erc1155-sale-native-token-testnet'
4545

4646
export const Connected = () => {
4747
const [isOpenCustomCheckout, setIsOpenCustomCheckout] = React.useState(false)
@@ -413,78 +413,16 @@ export const Connected = () => {
413413
return
414414
}
415415

416-
// NATIVE token sale
417-
const currencyAddress = zeroAddress
418-
const salesContractAddress = '0xf0056139095224f4eec53c578ab4de1e227b9597'
419-
const collectionAddress = '0x92473261f2c26f2264429c451f70b0192f858795'
420-
const price = '200000000000000'
421-
const contractId = '674eb55a3d739107bbd18ecb'
422-
423-
// // ERC-20 contract
424-
// const currencyAddress = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359'
425-
// const salesContractAddress = '0xe65b75eb7c58ffc0bf0e671d64d0e1c6cd0d3e5b'
426-
// const collectionAddress = '0xdeb398f41ccd290ee5114df7e498cf04fac916cb'
427-
// const price = '200000'
428-
// const contractId = '674eb5613d739107bbd18ed2'
429-
430-
const collectibles = [
431-
{
432-
tokenId: '1',
433-
quantity: '1'
434-
}
435-
]
436-
437-
const purchaseTransactionData = encodeFunctionData({
438-
abi: ERC_1155_SALE_CONTRACT,
439-
functionName: 'mint',
440-
// [to, tokenIds, amounts, data, expectedPaymentToken, maxTotal, proof]
441-
args: [
442-
address,
443-
collectibles.map(c => BigInt(c.tokenId)),
444-
collectibles.map(c => BigInt(c.quantity)),
445-
toHex(0),
446-
currencyAddress,
447-
price,
448-
[toHex(0, { size: 32 })]
449-
]
450-
})
451-
452-
// ERC-721 contract
453-
// const currencyAddress = '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359'
454-
// const salesContractAddress = '0xa0284905d29cbeb19f4be486f9091fac215b7a6a'
455-
// const collectionAddress = '0xd705db0a96075b98758c4bdafe8161d8566a68f8'
456-
// const price = '1'
457-
// const contractId = '674eb5613d739107bbd18ed2'
458-
459-
// const chainId = 137
460-
461-
// const collectibles = [
462-
// {
463-
// quantity: '1'
464-
// }
465-
// ]
466-
467-
// const purchaseTransactionData = encodeFunctionData({
468-
// abi: ERC_721_SALE_CONTRACT,
469-
// functionName: 'mint',
470-
// // [to, amount, expectedPaymentToken, maxTotal, proof]
471-
// args: [address, BigInt(1), currencyAddress, price, [toHex(0, { size: 32 })]]
472-
// })
416+
const creditCardProvider = checkoutProvider || 'forte'
473417

474418
openSelectPaymentModal({
475-
collectibles,
476-
chain: chainId,
477-
price,
478-
targetContractAddress: salesContractAddress,
479419
recipientAddress: address,
480-
currencyAddress,
481-
collectionAddress,
482-
creditCardProviders: [checkoutProvider || 'transak'],
420+
creditCardProviders: [creditCardProvider],
483421
onRampProvider: onRampProvider ? (onRampProvider as TransactionOnRampProvider) : TransactionOnRampProvider.transak,
484422
transakConfig: {
485-
contractId
423+
contractId: '674eb5613d739107bbd18ed2'
486424
},
487-
onSuccess: (txnHash: string) => {
425+
onSuccess: (txnHash?: string) => {
488426
console.log('success!', txnHash)
489427
},
490428
onError: (error: Error) => {
@@ -493,7 +431,7 @@ export const Connected = () => {
493431
onClose: () => {
494432
console.log('modal closed!')
495433
},
496-
txData: purchaseTransactionData
434+
...checkoutPresets[checkoutPreset as keyof typeof checkoutPresets](address || '')
497435
})
498436
}
499437

examples/react/src/components/CustomCheckout/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const CustomCheckout = () => {
5959
contractId,
6060
apiKey: '5911d9ec-46b5-48fa-a755-d59a715ff0cf'
6161
},
62-
onSuccess: (txnHash: string) => {
62+
onSuccess: (txnHash?: string) => {
6363
console.log('success!', txnHash)
6464
},
6565
onError: (error: Error) => {

examples/react/src/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const walletType: WalletType = searchParams.get('type') === 'universal' ? 'unive
1515
const isDebugMode = searchParams.has('debug')
1616
// @ts-ignore
1717
const isDev = __SEQUENCE_WEB_SDK_IS_DEV__
18-
const projectAccessKey = isDev ? 'AQAAAAAAAAK2JvvZhWqZ51riasWBftkrVXE' : 'AQAAAAAAAEGvyZiWA9FMslYeG_yayXaHnSI'
18+
const projectAccessKey = isDev ? 'AQAAAAAAAAbRfXdDS5e-ZD2pNeMcCtNnij4' : 'AQAAAAAAAEGvyZiWA9FMslYeG_yayXaHnSI'
1919
const walletConnectProjectId = 'c65a6cb1aa83c4e24500130f23a437d8'
2020

2121
export const sponsoredContractAddresses: Record<number, `0x${string}`> = {
@@ -184,7 +184,8 @@ export const checkoutConfig: SequenceCheckoutConfig = {
184184
sardineCheckoutUrl: 'https://sardine-checkout-sandbox.sequence.info',
185185
sardineOnRampUrl: 'https://crypto.sandbox.sardine.ai/',
186186
transakApiUrl: 'https://global-stg.transak.com',
187-
transakApiKey: 'c20f2a0e-fe6a-4133-8fa7-77e9f84edf98'
187+
transakApiKey: 'c20f2a0e-fe6a-4133-8fa7-77e9f84edf98',
188+
forteWidgetUrl: 'https://payments.sandbox.lemmax.com/forte-payments-widget.js'
188189
}
189190
: undefined
190191
}

0 commit comments

Comments
 (0)