-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* update readmes * Update README.md * Update README.md * update ai-chat readme * update nft-stripe-checkout readme
- Loading branch information
1 parent
346f3b3
commit b09f080
Showing
2 changed files
with
256 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,151 @@ | ||
## NFT Stripe Checkout | ||
# nft-stripe-checkout | ||
|
||
**DEMO:** https://nft-stripe-checkout.mintbase.xyz/ | ||
|
||
NFT-Stripe-Checkout is a Next.js project that provides a checkout interface for purchasing NFTs using Stripe. It uses the Mintbase Wallet for user authentication. | ||
|
||
## Get in touch | ||
[Demo](https://nft-stripe-checkout.mintbase.xyz) | ||
|
||
- Support: [Join the Telegram](https://tg.me/mintdev) | ||
- Twitter: [@mintbase](https://twitter.com/mintbase) | ||
## Setup | ||
|
||
1. First [deploy](https://mintbase.xyz/auth) a Mintbase Contract | ||
|
||
2. Add `mintbus.testnet` as a minter to deployed contract contract | ||
|
||
### Environment Variables | ||
|
||
|
||
Checkout `.env.example` and create a local env file (`.env.local`) with: | ||
|
||
``` | ||
NEXT_PUBLIC_NFT_CONTRACT_ADDRESS="stripeteststore.mintspace2.testnet" | ||
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="" | ||
NEXT_PUBLIC_MINTBASE_WALLET_URL="https://testnet.wallet.mintbase.xyz" | ||
NEXT_PUBLIC_NETWORK="testnet" | ||
``` | ||
|
||
### Develop | ||
|
||
To get started with the project, you need to install the dependencies first. Run the following command in your terminal: | ||
|
||
``` | ||
pnpm install | ||
``` | ||
|
||
After installing the dependencies, you can start the development server: | ||
|
||
``` | ||
pnpm run dev | ||
``` | ||
|
||
Then, open http://localhost:3000 with your browser to see the result. | ||
|
||
## Code Examples | ||
|
||
### Purchase Page | ||
|
||
The Purchase Page is located in `/src/app/page.tsx`. It uses the `useMbWallet` hook from the `@mintbase-js/react` package to manage the wallet state. The `onClick` function sends a POST request to create a payment intent: | ||
|
||
```ts | ||
|
||
--- | ||
function PurchasePage() { | ||
const [clientSecret, setClientSecret] = useState(""); | ||
|
||
const { activeAccountId, isConnected } = useMbWallet(); | ||
|
||
1. Deploy a mintbase contract | ||
2. Add `mintbus.testnet` as a minter to that contract | ||
const onClick = async () => { | ||
const resp = await fetch( | ||
"https://stripe2near-z3w7d7dnea-ew.a.run.app/payment-intent", | ||
{ | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ | ||
priceUsd: constants.priceUsd, | ||
action: mint({ | ||
metadata: { | ||
reference: "NiztQFL98n8MgYKSu7FL3vdUnU_eUlM3fsQ0o3JEQCY", | ||
media: "eUdPgtRlT9Ua8ZHsGuNi1P8TUfVJaGUTH42NB1i1s4E", | ||
}, | ||
ownerId: activeAccountId!, | ||
contractAddress: constants.tokenContractAddress, | ||
}), | ||
}), | ||
} | ||
); | ||
if (resp.ok) { | ||
const json = await resp.json(); | ||
setClientSecret(json.clientSecret); | ||
} | ||
}; | ||
|
||
``` | ||
### Credit Card Form | ||
The Credit Card Form is located in nft-stripe-checkout/src/app/page.tsx. It uses the useStripe and useElements hooks from the @stripe/react-stripe-js package to manage the Stripe elements and confirm the payment: | ||
```ts | ||
|
||
const CreditCardForm = () => { | ||
const elements = useElements(); | ||
const stripe = useStripe(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const [isCompleted, setIsCompleted] = useState(false); | ||
|
||
const onClick = async () => { | ||
if (!stripe || !elements) { | ||
return; | ||
} | ||
|
||
setIsLoading(true); | ||
|
||
try { | ||
const { paymentIntent, error } = await stripe.confirmPayment({ | ||
elements, | ||
confirmParams: { | ||
return_url: "http://localhost:3000", | ||
}, | ||
redirect: "if_required", | ||
}); | ||
if (error) { | ||
throw error.message; | ||
} | ||
if (paymentIntent.status === "succeeded") { | ||
alert( | ||
"Payment success. The NFT will be delivered to your wallet shortly." | ||
); | ||
setIsCompleted(true); | ||
} else { | ||
alert("Payment failed. Please try again."); | ||
} | ||
} catch (e) { | ||
alert(`There was an error with the payment. ${e}`); | ||
} | ||
|
||
setIsLoading(false); | ||
}; | ||
|
||
return ( | ||
<> | ||
<PaymentElement /> | ||
|
||
<button | ||
className="bg-blue-600 hover:bg-blue-500 text-white font-bold py-2 px-4 rounded-lg w-full" | ||
onClick={onClick} | ||
disabled={isLoading || isCompleted || !stripe || !elements} | ||
> | ||
{isCompleted | ||
? "Payment received" | ||
: isLoading | ||
? "Please wait..." | ||
: "Pay now"} | ||
</button> | ||
</> | ||
); | ||
}; | ||
|
||
``` | ||
## Get in touch | ||
- Support: [Join the Telegram](https://tg.me/mintdev) | ||
- Twitter: [@mintbase](https://twitter.com/mintbase) |
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-starter-react-vite – ./starter/react-vite
templates-starter-react-vite-git-main-mintbase.vercel.app
starter-react-vite.vercel.app
starter-react-vite.mintbase.xyz
templates-starter-react-vite-mintbase.vercel.app
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-nft-stripe-checkout – ./nft-stripe-checkout
nft-stripe-checkout.vercel.app
nft-stripe-checkout.mintbase.xyz
templates-nft-stripe-checkout-git-main-mintbase.vercel.app
templates-nft-stripe-checkout-mintbase.vercel.app
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-simple-minter – ./minter
templates-simple-minter-mintbase.vercel.app
templates-simple-minter-git-main-mintbase.vercel.app
minter.mintbase.xyz
minter-template.vercel.app
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-starter – ./starter/next-js
templates-starter-mintbase.vercel.app
mintbase-starter.vercel.app
templates-starter-git-main-mintbase.vercel.app
starter.mintbase.xyz
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-contract-deployer – ./contract-deployer
templates-contract-deployer-mintbase.vercel.app
templates-contract-deployer-git-main-mintbase.vercel.app
contract-deployer-template.vercel.app
contract-deployer-template.mintbase.xyz
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-ai-minter – ./ai-minter
templates-ai-minter-git-main-mintbase.vercel.app
ai-minter.vercel.app
ai-minter.mintbase.xyz
templates-ai-minter-mintbase.vercel.app
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates – ./
templates-mintbase.vercel.app
templates-git-main-mintbase.vercel.app
templates-theta.vercel.app
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-ai-chat – ./ai-chat
ai-chat-template-mintbase.vercel.app
templates-ai-chat-mintbase.vercel.app
templates-ai-chat-git-main-mintbase.vercel.app
ai-chat.mintbase.xyz
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-token-drop – ./simple-token-drop
templates-token-drop-git-main-mintbase.vercel.app
token-drop-template.mintbase.xyz
templates-token-drop-mintbase.vercel.app
token-drop-template.vercel.app
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-marketplace – ./marketplace
templates-marketplace-git-main-mintbase.vercel.app
templates-marketplace-mintbase.vercel.app
marketplace-template.vercel.app
marketplace-template.mintbase.xyz
b09f080
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
templates-blogchain – ./blogchain
blogchain-template.vercel.app
templates-blogchain-mintbase.vercel.app
blogchain.mintbase.xyz
templates-blogchain-git-main-mintbase.vercel.app