@codearcade/expo-markdown 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # razorpay-expo
2
+
3
+ A modern, maintained Razorpay SDK for **Expo** and **React Native**.
4
+
5
+ Built as a community replacement for the outdated official Razorpay
6
+ React Native SDK.
7
+
8
+ <p align="center">
9
+ <img src="docs/demo.gif" alt="Razorpay Expo Demo" width="360" />
10
+ </p>
11
+
12
+ <p align="center">
13
+ <em>Quick demo of the Razorpay Expo SDK in action</em>
14
+ </p>
15
+
16
+ ---
17
+
18
+ ## ✨ Features
19
+
20
+ - Works with Expo (WebView-based)
21
+ - Modern API with hooks & provider
22
+ - No outdated native dependencies
23
+ - Designed for real production usage
24
+
25
+ ---
26
+
27
+ ## Installation
28
+
29
+ First, install the package and its peer dependencies:
30
+
31
+ ```bash
32
+ npm install razorpay-expo
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ There are two ways to use this library:
38
+
39
+ 1. **Provider & Hook Usage** (`<RazorpayProvider>` & `useRazorpay`) - **Preferred**.
40
+ 2. **Direct Component Usage** (`<RazorpayCheckout />`) - Manual state management.
41
+
42
+ ### Method 1: Provider & Hook (Recommended)
43
+
44
+ This approach lets you trigger checkout from anywhere in your app.
45
+
46
+ **1️⃣ Wrap your app with `RazorpayProvider`**
47
+
48
+ ```tsx
49
+ // _layout.tsx or App.tsx
50
+ import { RazorpayProvider } from "razorpay-expo";
51
+
52
+ export default function RootLayout() {
53
+ return (
54
+ <RazorpayProvider>
55
+ <Slot />
56
+ </RazorpayProvider>
57
+ );
58
+ }
59
+ ```
60
+
61
+ **2️⃣ Use `useRazorpay` in your components**
62
+
63
+ ```tsx
64
+ import React from "react";
65
+ import { Button } from "react-native";
66
+ import { useRazorpay } from "razorpay-expo";
67
+ import { useRouter } from "expo-router";
68
+
69
+ export default function PaymentScreen() {
70
+ const { openCheckout, closeCheckout } = useRazorpay();
71
+ const router = useRouter();
72
+
73
+ const handleBuy = async () => {
74
+ // 1. Create order on your backend
75
+ // const { orderId, currency, amount } = await createOrderOnBackend();
76
+
77
+ // For demo purposes:
78
+ const currency = "INR";
79
+ const amount = 100;
80
+ const orderId = "order_RPNBJhnTs2Lq0B"; // Replace with actual order_id from backend
81
+
82
+ openCheckout(
83
+ {
84
+ key: "YOUR_RAZORPAY_KEY",
85
+ currency: currency,
86
+ amount: amount,
87
+ order_id: orderId, // Mandatory: either order_id or subscription_id
88
+ name: "Test Company",
89
+ image: "https://codearcade.io/logos/logo.png",
90
+ description: "Test Transaction",
91
+ prefill: {
92
+ name: "John Doe",
93
+ email: "test@example.com",
94
+ contact: "1234567890",
95
+ },
96
+ theme: {
97
+ color: "#ffd35c",
98
+ },
99
+ },
100
+ {
101
+ onSuccess: (data) => {
102
+ console.log("Payment Success:", data);
103
+ closeCheckout();
104
+
105
+ // Navigate to success screen
106
+ router.replace({
107
+ pathname: "/success",
108
+ params: {
109
+ paymentId: data.razorpay_payment_id,
110
+ amount: amount.toString(),
111
+ date: new Date().toISOString(),
112
+ },
113
+ });
114
+ },
115
+ onFailure: (error) => {
116
+ console.log("Payment Failed:", error);
117
+ },
118
+ onClose: () => {
119
+ console.log("Widget closed");
120
+ },
121
+ },
122
+ );
123
+ };
124
+
125
+ return <Button title="Buy Now" onPress={handleBuy} />;
126
+ }
127
+ ```
128
+
129
+ ### Method 2: Direct Component Usage
130
+
131
+ Use RazorpayCheckout directly and control visibility yourself.
132
+
133
+ ```tsx
134
+ import React, { useState } from "react";
135
+ import { View, Text, Button, SafeAreaView } from "react-native";
136
+ import { RazorpayCheckout } from "razorpay-expo";
137
+
138
+ export default function App() {
139
+ const [open, setOpen] = useState(false);
140
+
141
+ return (
142
+ <SafeAreaView style={{ flex: 1 }}>
143
+ <View>
144
+ <Text>Home</Text>
145
+ <Button title="Buy Now" onPress={() => setOpen(true)} />
146
+
147
+ {open && (
148
+ <RazorpayCheckout
149
+ options={{
150
+ key: "YOUR_RAZORPAY_KEY", // e.g., rzp_test_...
151
+ currency: "INR",
152
+ amount: 100, // Amount in lowest denomination (e.g. 100 paise = 1 INR)
153
+ order_id: "order_RPNBJhnTs2Lq0B", // OR subscription_id
154
+ name: "Test Company",
155
+ image: "https://codearcade.io/logos/logo.png",
156
+ description: "Test Transaction",
157
+ prefill: {
158
+ name: "John Doe",
159
+ email: "test@example.com",
160
+ contact: "1234567890",
161
+ },
162
+ notes: {
163
+ order_id: "1",
164
+ payment_id: "1",
165
+ },
166
+ theme: {
167
+ color: "#ffd35c",
168
+ },
169
+ }}
170
+ onSuccess={(data) => console.log("Success:", data)}
171
+ onFailure={(error) => console.log("Failure:", error)}
172
+ onClose={() => setOpen(false)}
173
+ />
174
+ )}
175
+ </View>
176
+ </SafeAreaView>
177
+ );
178
+ }
179
+ ```
180
+
181
+ ## API Reference
182
+
183
+ ### `RazorpayCheckout` Props
184
+
185
+ | Prop | Type | Description |
186
+ | ----------- | ---------------------- | ---------------------------------------------------------------------- |
187
+ | `options` | `RazorpayOptions` | Configuration object for Razorpay checkout. |
188
+ | `onSuccess` | `(data: any) => void` | Callback function triggered on successful payment. |
189
+ | `onFailure` | `(error: any) => void` | Callback function triggered on payment failure. |
190
+ | `onClose` | `() => void` | Callback function triggered when the checkout close button is pressed. |
191
+
192
+ ### `useRazorpay` Hook
193
+
194
+ Returns:
195
+
196
+ - `openCheckout(options: RazorpayOptions, callbacks: RazorpayCallbacks)`: Function to open the checkout.
197
+ - `closeCheckout()`: Function to manually close the checkout (useful in `onSuccess`).
198
+
199
+ ### `RazorpayOptions`
200
+
201
+ | Field | Type | Required | Description |
202
+ | ----------------- | -------- | --------- | ----------------------------------------------------------------------------------------- |
203
+ | `key` | `string` | **Yes** | Your Razorpay Key ID. |
204
+ | `amount` | `number` | **Yes** | Amount in lowest currency unit (e.g., paise). |
205
+ | `currency` | `string` | **Yes** | Currency code (e.g., "INR"). |
206
+ | `order_id` | `string` | **Yes\*** | Order ID generated from backend. (\*Either `order_id` or `subscription_id` is mandatory). |
207
+ | `subscription_id` | `string` | **Yes\*** | Subscription ID for recurring payments. |
208
+ | `name` | `string` | No | Name of your company/app. |
209
+ | `description` | `string` | No | Description of the transaction. |
210
+ | `image` | `string` | No | URL to your logo. |
211
+ | `prefill` | `object` | No | Object containing `name`, `email`, `contact`. |
212
+ | `theme` | `object` | No | Object containing `color` (hex code). |
213
+
214
+ - Either order_id or subscription_id is required.
215
+
216
+ ⚠️ Disclaimer
217
+ This is an independent, community-maintained project and is not affiliated
218
+ with or endorsed by Razorpay or Expo.
219
+
220
+ ## License
221
+
222
+ MIT
@@ -0,0 +1,21 @@
1
+ import React from "react";
2
+ interface Props {
3
+ content: string;
4
+ theme?: "light" | "dark";
5
+ defaultDarkTheme?: {
6
+ backgroundColor: string;
7
+ textColor: string;
8
+ codeBackgroundColor: string;
9
+ primaryColor: string;
10
+ secondaryColor: string;
11
+ };
12
+ defaultLightTheme?: {
13
+ backgroundColor: string;
14
+ textColor: string;
15
+ codeBackgroundColor: string;
16
+ primaryColor: string;
17
+ secondaryColor: string;
18
+ };
19
+ }
20
+ export declare const Markdown: React.FC<Props>;
21
+ export {};
@@ -0,0 +1 @@
1
+ export * from "./components/markdown";