Skip to content
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
c6938ac
created checkouts folder
gerrysaporito Oct 19, 2023
5ca0131
moved over paper code
gerrysaporito Oct 19, 2023
627a9e6
Merge branch 'main' of https://github.com/thirdweb-dev/js into gerry_…
gerrysaporito Oct 19, 2023
e51f987
updated readme and package.json
gerrysaporito Oct 19, 2023
3695842
yarn install
gerrysaporito Oct 19, 2023
92e859e
fix build errors
gerrysaporito Oct 19, 2023
f7a6f9c
fixed lint errors
gerrysaporito Oct 20, 2023
1a8fcc0
updated changelog
gerrysaporito Oct 20, 2023
2fcd734
format
gerrysaporito Oct 20, 2023
924746d
Merge branch 'main' of https://github.com/thirdweb-dev/js into gerry_…
gerrysaporito Oct 20, 2023
a4a66bd
updated package.json
gerrysaporito Oct 20, 2023
526ddac
updated exports
gerrysaporito Oct 20, 2023
aacefe5
updated pnpm
gerrysaporito Oct 20, 2023
2bac612
updated packages
gerrysaporito Oct 20, 2023
e85ba5a
updated package.json
gerrysaporito Oct 20, 2023
c546c87
updating packages
IDubuque Oct 26, 2023
6a6b22c
rename to payments
IDubuque Oct 26, 2023
3d766bc
remove env var THIRDWEB_PAYMENTS_SDK_VERSION
IDubuque Oct 26, 2023
c28dd1f
inherit packages
IDubuque Oct 26, 2023
d63932e
remove solana
IDubuque Oct 26, 2023
44faa48
ews.thirdweb.com -> payments.thirdweb.com
IDubuque Oct 26, 2023
b002cf2
rm CreateWallet.ts
IDubuque Oct 26, 2023
02c7076
remove @paperxyz/sdk-common-utilities package
IDubuque Oct 27, 2023
06013ae
updating pnpm-lock.yaml
IDubuque Oct 30, 2023
602fa8c
fixing build issues
IDubuque Oct 30, 2023
d105e1f
fix build
IDubuque Oct 30, 2023
5074246
adding changeset
IDubuque Oct 30, 2023
ea272d4
fix package.json path
IDubuque Oct 31, 2023
3142a84
add versions to iframes
IDubuque Oct 31, 2023
875fcc3
copy paper-react files over
IDubuque Oct 31, 2023
226f809
remove CreateWallet component
IDubuque Oct 31, 2023
f55fe83
updating /payments exports
IDubuque Oct 31, 2023
6a50e28
changing imports to /payments
IDubuque Oct 31, 2023
565ae2b
update lock file
IDubuque Oct 31, 2023
74d3685
remove * exports from thirdweb-checkout
IDubuque Nov 1, 2023
fc41146
only export public interfaces
IDubuque Nov 1, 2023
7a8d428
exporting @paperxyz/react-client-sdk
IDubuque Nov 1, 2023
9505ea4
change data-paper-sdk-version metadata
IDubuque Nov 1, 2023
5eee39c
add clientId to CheckoutWithCard intf
IDubuque Nov 9, 2023
b34c629
updating packages
IDubuque Nov 9, 2023
b212251
add clientId to createCheckoutWithCardElement
IDubuque Nov 14, 2023
83c6394
passing clientId to backend
IDubuque Nov 14, 2023
d035b79
Merge branch 'main' into isaac/react_sdk_migration
IDubuque Dec 15, 2023
b3c3229
add pointer events update to modal
IDubuque Dec 15, 2023
9af4480
added changed / unchanged comments
IDubuque Dec 16, 2023
af927e0
update incorrect paths
IDubuque Dec 16, 2023
e8f1a28
remove ethers peerDependency
IDubuque Dec 16, 2023
b474290
rename PaperSdkProvider to PaymentsSdkProvider
IDubuque Dec 16, 2023
75a618d
updated turbo
IDubuque Dec 16, 2023
4e4bcd3
fix build issues
IDubuque Dec 16, 2023
9a2b473
lint fix
IDubuque Dec 16, 2023
577d5b0
changed require to import
IDubuque Dec 16, 2023
bb927d9
build fix
IDubuque Dec 16, 2023
7fa35f4
fix lint / build issues
IDubuque Dec 16, 2023
5eceb50
remove payments/changelog
IDubuque Jan 2, 2024
c87ae7e
add native tw domain
IDubuque Jan 3, 2024
1c34853
changeset major + description
IDubuque Jan 3, 2024
f7bccde
change payments package version
IDubuque Jan 3, 2024
64fa402
change PaperSDKError typename to PaymentsSDKError
IDubuque Jan 3, 2024
e447c5a
added minor changeset for react sdk
IDubuque Jan 3, 2024
3f481cb
fix security issue
IDubuque Jan 3, 2024
93593ed
Merge branch 'main' into isaac/react_sdk_migration
IDubuque Jan 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mean-ducks-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@thirdweb-dev/payments": patch
---

Initial dev version
11 changes: 11 additions & 0 deletions packages/payments/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
"@babel/preset-typescript",
["@babel/preset-env", { "targets": "defaults, not ie 11" }]
],
"plugins": [
"@babel/plugin-transform-flow-strip-types",
"@babel/plugin-transform-private-methods",
"@babel/plugin-proposal-class-properties"
]
}
4 changes: 4 additions & 0 deletions packages/payments/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# folders
dist/

# files
21 changes: 21 additions & 0 deletions packages/payments/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
root: true,
extends: ["thirdweb"],
plugins: ["better-tree-shaking"],
rules: {
"better-tree-shaking/no-top-level-side-effects": "error",
"no-restricted-imports": [
"error",
{
paths: [
{
name: "eventemitter3",
importNames: ["EventEmitter"],
message:
"Do not use named import for importing EventEmitter, Use default import instead.",
},
],
},
],
},
};
5 changes: 5 additions & 0 deletions packages/payments/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 0.1.0

### Minor Changes

- [#420](https://github.com/thirdweb-dev/js/pull/420) [`639e535`](https://github.com/thirdweb-dev/js/commit/639e535ed55280ad9d081001aab3f5af72bb3e45) Thanks [@gerrysaporito](https://github.com/gerrysaporito)! - Init checkouts package
14 changes: 14 additions & 0 deletions packages/payments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<p align="center">
<br />
<a href="https://thirdweb.com"><img src="https://github.com/thirdweb-dev/js/blob/main/packages/sdk/logo.svg?raw=true" width="200" alt=""/></a>
<br />
</p>
<h1 align="center">thirdweb Checkouts SDK</h1>
<p align="center">
<a href="https://www.npmjs.com/package/@thirdweb-dev/payments"><img src="https://img.shields.io/npm/v/@thirdweb-dev/payments?color=red&label=npm&logo=npm" alt="npm version"/></a>
<a href="https://github.com/thirdweb-dev/js/actions/workflows/build-test-lint.yml"><img alt="Build Status" src="https://github.com/thirdweb-dev/js/actions/workflows/build-test-lint.yml/badge.svg"/></a>
<a href="https://discord.gg/thirdweb"><img alt="Join our Discord!" src="https://img.shields.io/discord/834227967404146718.svg?color=7289da&label=discord&logo=discord&style=flat"/></a>

</p>
<p align="center"><strong>web3 Checkouts library to integrate any NFT checkout into your applications.</strong></p>
<br />
58 changes: 58 additions & 0 deletions packages/payments/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@thirdweb-dev/payments",
"version": "1.0.0",
"main": "dist/thirdweb-dev-payments.cjs.js",
"module": "dist/thirdweb-dev-payments.esm.js",
"types": "dist/thirdweb-dev-payments.cjs.d.ts",
"browser": {
"./dist/thirdweb-dev-payments.esm.js": "./dist/thirdweb-dev-payments.browser.esm.js"
},
"exports": {
".": {
"module": {
"browser": "./dist/thirdweb-dev-payments.browser.esm.js",
"default": "./dist/thirdweb-dev-payments.esm.js"
},
"default": "./dist/thirdweb-dev-payments.cjs.js"
},
"./package.json": "./package.json"
},
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/payments",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/thirdweb-dev/js/issues"
},
"author": "thirdweb eng <[email protected]>",
"files": [
"dist/"
],
"preconstruct": {
"entrypoints": [
"index.ts"
],
"exports": {
"envConditions": [
"browser"
]
}
},
"sideEffects": false,
"dependencies": {
"ethers": "^5.7.2"
},
"devDependencies": {
"@thirdweb-dev/tsconfig": "workspace:*",
"eslint-config-thirdweb": "workspace:*",
"typescript": "^5.1.6",
"@preconstruct/cli": "2.7.0"
},
"scripts": {
"format": "prettier --write 'src/**/*'",
"lint": "eslint src/",
"fix": "eslint src/ --fix",
"clean": "rm -rf dist/",
"build": "tsc && preconstruct build",
"preconstruct:fix": "preconstruct fix",
"push": "yalc push"
}
}
56 changes: 56 additions & 0 deletions packages/payments/src/constants/blockchain.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// UNCHANGED: MERGED FROM sdk-common-utilities/blockchain
export const ChainToPublicRpc: Record<Chain, string> = {
Ethereum: "https://ethereum.rpc.thirdweb.com",
Goerli: "https://goerli.rpc.thirdweb.com",
Mumbai: "https://mumbai.rpc.thirdweb.com",
Polygon: "https://polygon.rpc.thirdweb.com",
Avalanche: "https://avalanche.rpc.thirdweb.com",
Optimism: "https://optimism.rpc.thirdweb.com",
OptimismGoerli: "https://optimism-goerli.rpc.thirdweb.com",
BSC: "https://binance.rpc.thirdweb.com",
BSCTestnet: "https://binance-testnet.rpc.thirdweb.com",
ArbitrumOne: "https://arbitrum.rpc.thirdweb.com",
ArbitrumGoerli: "https://arbitrum-goerli.rpc.thirdweb.com",
Fantom: "https://fantom.rpc.thirdweb.com",
FantomTestnet: "https://fantom-testnet.rpc.thirdweb.com",
Sepolia: "https://sepolia.rpc.thirdweb.com",
AvalancheFuji: "https://avalanche-fuji.rpc.thirdweb.com",
};

export const ChainIdToChain: Record<number, Chain> = {
1: "Ethereum",
5: "Goerli",
80001: "Mumbai",
137: "Polygon",
43114: "Avalanche",
10: "Optimism",
420: "OptimismGoerli",
56: "BSC",
97: "BSCTestnet",
42161: "ArbitrumOne",
421613: "ArbitrumGoerli",
250: "Fantom",
4002: "FantomTestnet",
11155111: "Sepolia",
43113: "AvalancheFuji",
};

// General Embedded wallet types
export type Chain =
| "Polygon"
| "Mumbai"
| "Goerli"
| "Ethereum"
| "Avalanche"
| "Optimism"
| "OptimismGoerli"
| "BSC"
| "BSCTestnet"
| "ArbitrumOne"
| "ArbitrumGoerli"
| "Fantom"
| "FantomTestnet"
| "Sepolia"
| "AvalancheFuji";

export type SupportedChainName = Chain | "Rinkeby";
12 changes: 12 additions & 0 deletions packages/payments/src/constants/iframeMessages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// UNCHANGED: MERGED FROM sdk-common-utilities/iframeMessages
export type MessageType<T> =
| {
eventType: string;
success: true;
data: T;
}
| {
eventType: string;
success: false;
error: string;
};
4 changes: 4 additions & 0 deletions packages/payments/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// CHANGED: export merged sdk-common-utilities/constants & js-client-sdk/constants
export * from "./settings";
export * from "./blockchain";
export * from "./style";
32 changes: 32 additions & 0 deletions packages/payments/src/constants/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// UNCHANGED: MERGE BETWEEN sdk-common-utilities/settings and js-client-sdk/settings
const isDev = (): boolean => {
return !!(
typeof window !== "undefined" &&
window.localStorage.getItem("IS_PAPER_DEV") === "true"
);
};

const isOldPaperDomain = (): boolean =>
typeof window !== "undefined" && window.location.origin.includes("paper.xyz");

export const getPaperOriginUrl = (): string => {
if (isDev()) {
return (
window.localStorage.getItem("PAPER_DEV_URL") ?? "http://localhost:3000"
);
}

if (isOldPaperDomain()) {
return window.location.origin;
}

return "https://payments.thirdweb.com";
};

// eslint-disable-next-line better-tree-shaking/no-top-level-side-effects
export const PAPER_APP_URL = getPaperOriginUrl();

export const CHECKOUT_WITH_ETH_IFRAME_URL = "/sdk/2022-08-12/checkout-with-eth";
export const CHECKOUT_WITH_CARD_IFRAME_URL =
"/sdk/2022-08-12/checkout-with-card";
export const CREATE_WALLET_IFRAME_URL = "/sdk/v2/verify-email";
25 changes: 25 additions & 0 deletions packages/payments/src/constants/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// // UNCHANGED: MERGED FROM sdk-common-utilities/style
export type StyleObject = Partial<CSSStyleDeclaration>;

export interface ICustomizationOptions {
colorPrimary?: string;
colorBackground?: string;
colorText?: string;
borderRadius?: number;
fontFamily?: string;

inputBackgroundColor?: string;
inputBorderColor?: string;
}
export type CustomizationOptionsType = {
[key in keyof ICustomizationOptions]: string;
};
export type Locale = "en" | "fr" | "es" | "it" | "de" | "ja" | "ko" | "zh";

export const DEFAULT_BRAND_OPTIONS = {
colorPrimary: "#cf3781",
colorBackground: "#ffffff",
colorText: "#1a202c",
borderRadius: 12,
fontFamily: "Open Sans",
};
8 changes: 8 additions & 0 deletions packages/payments/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// CHANGED: exports

// Customization options and base urls
export * from "./constants";
// Types
export * from "./interfaces";
// Components
export * from "./lib";
67 changes: 67 additions & 0 deletions packages/payments/src/interfaces/CheckoutWithCard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// UNCHANGED

export interface ReviewResult {
/**
* A unique ID for this purchase.
*/
id: string;

/**
* The cardholder's full name provided by the buyer.
*/
cardholderName: string;
}

export interface KycModal {
iframeLink: string;
}

/**
* The ICheckoutWithCardConfigs interface defines the configuration options for the checkoutWithCard component provided by Paper.
* This component allows users to generate a card payment component for NFTs without needing any backend calls.
*
* The configuration options include:
*
* - `contractId`: The id of your contract (not the address) found in you seller dashboard.
* - `walletAddress`: The wallet address to which the payment will be sent (AKA the receiving wallet).
* - `email`: (Optional) Email address of the buyer.
* - `quantity`: (Optional) The number of items to be purchased.
* - `metadata`: (Optional) A record of additional information about the transaction.
* - `mintMethod`: (Optional, Only required for Custom Contract Types) The contract function name, function args, and payment information which will be sent to your contract.
* - `contractArgs`: (Optional) Depending on the contract type, this can defined additional args to call your contract with. See [Thirdweb/Reservoir docs](https://docs.withpaper.com/reference/thirdweb-contracts) for more details.
* - `feeBearer`: (Optional) Who will bear the transaction fee, either 'BUYER' or 'SELLER'.
* - `capturePaymentLater`: (Optional) If set to true, the payment is authorized but not captured immediately.
* - `fiatCurrency`: (Optional) The type of fiat currency for the payment.
* - `title`: (Optional) The title to be displayed on the Stripe receipt.
* - `sendEmailOnTransferSucceeded`: (Optional) If set to true, an email is sent when the transfer succeeds.
* - `postPurchaseMessageMarkdown`: (Optional) A post-purchase message in Markdown format.
* - `postPurchaseButtonText`: (Optional) The text for the post-purchase button.
* - `successCallbackUrl`: (Optional) The URL to be called back when the transaction is successful.
*
* Note: This interface is part of an open-source npm package. Please ensure you understand the implications of each field before using this interface.
*/
export interface ICheckoutWithCardConfigs {
contractId: string;
walletAddress: string;
email?: string;
quantity?: number;
mintMethod?: {
name: string;
args: Record<string, any>;
payment: { value: string; currency: string };
};
contractArgs?: Record<string, any>;

// payment customizations
capturePaymentLater?: boolean;
fiatCurrency?: string;

// stripe receipt
title?: string;

// email
sendEmailOnTransferSucceeded?: boolean;
postPurchaseMessageMarkdown?: string;
postPurchaseButtonText?: string;
successCallbackUrl?: string;
}
17 changes: 17 additions & 0 deletions packages/payments/src/interfaces/Modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// UNCHANGED

import type { StyleObject } from "../constants/style";

export interface ModalStyles {
main: StyleObject;
overlay: StyleObject;
body: StyleObject;
iframe: StyleObject;
closeButton?: StyleObject;
spinner: StyleObject;
}

export interface ModalInterface {
modalContainer?: HTMLElement;
modalStyles?: Partial<ModalStyles>;
}
31 changes: 31 additions & 0 deletions packages/payments/src/interfaces/PaperSDKError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// UNCHANGED

export type PaperSDKError = {
/**
* An enum representing the error encountered.
* The value is a human-readable, English message describing the error.
*/
code: PaperSDKErrorCode | PayWithCryptoErrorCode;
error: Error;
};

export enum PaperSDKErrorCode {
UserAbandonedCheckout = "User abandoned the checkout",
UserLoginFailed = "User login failed",
InvalidProps = "The props you passed in to this component are not valid.",
InvalidCard = "The card information is invalid. Please double check that the Card, CVC, and Zip code are all correct.",
EmailNotVerified = "The email was unable to be verified.",
NotEnoughSupply = "There is not enough supply to claim.",
AddressNotAllowed = "This address is not on the allowlist.",
NoActiveClaimPhase = "There is no active claim phase at the moment.",
}

export enum PayWithCryptoErrorCode {
ErrorConnectingToWallet = "Error connecting to wallet",
ErrorSendingTransaction = "Something went wrong sending transaction",
InsufficientBalance = `Insufficient ETH`,
TransactionCancelled = "Transaction Cancelled",
WrongChain = `Wrong Chain Detected`,
ChainSwitchUnderway = "There is a network switch already underway",
PendingSignature = "Pending Signature",
}
Loading