@astropay/payments-lib 0.0.11 → 0.1.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 CHANGED
@@ -35,6 +35,9 @@ AstroPay's official frontend library that allows you to easily embed customizabl
35
35
  - [AstroPayFullCheckout](#astropayfullcheckout)
36
36
  - [Props](#props)
37
37
  - [Example](#example)
38
+ - [AstroPayPayment](#astropaypayment)
39
+ - [Props](#props-1)
40
+ - [Example](#example-1)
38
41
  - [🎨 Styling \& Theming](#-styling--theming)
39
42
  - [Available Themes](#available-themes)
40
43
  - [Custom Styling](#custom-styling)
@@ -94,15 +97,20 @@ AstroPayCore.init('app-id', {
94
97
  });
95
98
 
96
99
  // Use the payment component in your application
97
- // Note: Make sure an HTML element with id="payment-container" exists in your DOM before running this code
98
- const paymentElement = document.getElementById('payment-container');
99
- const payment = new AstroPayFullCheckout({
100
+ const paymentComponent = new AstroPayFullCheckout({
100
101
  amount: 100,
101
102
  currency: 'USD',
102
103
  country: 'BR',
104
+ onSuccess: () => console.log('Payment successful'),
105
+ onError: () => console.error('Payment failed')
103
106
  });
104
107
 
105
- paymentElement.appendChild(payment.element);
108
+ // Render the component into a container element
109
+ const paymentElement = document.getElementById('payment-container');
110
+ paymentComponent.render(paymentElement);
111
+
112
+ // Later, when you want to clean up
113
+ // paymentComponent.destroy();
106
114
  ```
107
115
 
108
116
  ## 🧩 Components
@@ -113,13 +121,15 @@ The main component for rendering a payment interface.
113
121
 
114
122
  #### Props
115
123
 
116
- | Prop | Type | Required | Description |
117
- | --------------- | ------- | -------- | ------------------------------------------------------------ |
118
- | amount | number | Yes | The payment amount |
119
- | currency | string | Yes | The currency code (e.g., 'USD') |
120
- | country | string | Yes | The country code (e.g., 'BR', 'US') |
121
- | showTitle | boolean | No | Whether to show the component title (defaults to `true`) |
122
- | showDescription | boolean | No | Whether to show the payment description (defaults to `true`) |
124
+ | Prop | Type | Required | Description |
125
+ | --------------- | ---------- | -------- | ------------------------------------------------------------ |
126
+ | amount | number | Yes | The payment amount |
127
+ | currency | string | Yes | The currency code (e.g., 'USD') |
128
+ | country | string | Yes | The country code (e.g., 'BR', 'US') |
129
+ | showTitle | boolean | No | Whether to show the component title (defaults to `true`) |
130
+ | showDescription | boolean | No | Whether to show the payment description (defaults to `true`) |
131
+ | onSuccess | () => void | No | Callback function called when payment is successful |
132
+ | onError | () => void | No | Callback function called when payment fails |
123
133
 
124
134
  #### Example
125
135
 
@@ -133,10 +143,63 @@ const fullCheckoutComponent = new AstroPayFullCheckout({
133
143
  // Optional props
134
144
  showTitle: true,
135
145
  showDescription: true,
146
+ onSuccess: () => {
147
+ console.log('Payment was successful');
148
+ // Handle successful payment, e.g., redirect to success page
149
+ },
150
+ onError: () => {
151
+ console.error('Payment failed');
152
+ // Handle payment failure
153
+ }
136
154
  });
137
155
 
138
- // Note: Make sure an HTML element with id="payment-container" exists in your DOM before running this code
139
- document.getElementById('payment-container').appendChild(fullCheckoutComponent.element);
156
+ // Render the component into a container element
157
+ const container = document.getElementById('payment-container');
158
+ fullCheckoutComponent.render(container);
159
+
160
+ // Later, when you want to clean up (e.g., on page navigation)
161
+ // fullCheckoutComponent.destroy();
162
+ ```
163
+
164
+ ### AstroPayPayment
165
+
166
+ A streamlined payment component focused on AstroPay's native payment method.
167
+
168
+ #### Props
169
+
170
+ | Prop | Type | Required | Description |
171
+ | --------- | ---------- | -------- | --------------------------------------------------- |
172
+ | amount | number | Yes | The payment amount |
173
+ | currency | string | Yes | The currency code (e.g., 'USD') |
174
+ | country | string | Yes | The country code (e.g., 'BR', 'US') |
175
+ | onSuccess | () => void | No | Callback function called when payment is successful |
176
+ | onError | () => void | No | Callback function called when payment fails |
177
+
178
+ #### Example
179
+
180
+ ```typescript
181
+ import { AstroPayPayment } from '@astropay/payments-lib';
182
+
183
+ const paymentComponent = new AstroPayPayment({
184
+ amount: 100,
185
+ currency: 'USD',
186
+ country: 'BR',
187
+ onSuccess: () => {
188
+ console.log('Payment was successful');
189
+ // Handle successful payment, e.g., redirect to success page
190
+ },
191
+ onError: () => {
192
+ console.error('Payment failed');
193
+ // Handle payment failure
194
+ }
195
+ });
196
+
197
+ // Render the component into a container element
198
+ const container = document.getElementById('payment-container');
199
+ paymentComponent.render(container);
200
+
201
+ // Later, when you want to clean up (e.g., on page navigation)
202
+ // paymentComponent.destroy();
140
203
  ```
141
204
 
142
205
  ## 🎨 Styling & Theming
@@ -181,15 +244,17 @@ AstroPayCore.init('app-id', {
181
244
 
182
245
  #### Available Style Properties
183
246
 
184
- | Property | Type | Description |
185
- | ------------------ | ------ | ------------------------- |
186
- | primaryColor | string | Primary brand color |
187
- | secondaryColor | string | Secondary brand color |
188
- | backgroundColor | string | Background color |
189
- | textPrimaryColor | string | Primary text color |
190
- | textSecondaryColor | string | Secondary text color |
191
- | fontFamily | string | Font family |
192
- | width | number | Component width in pixels |
247
+ | Property | Type | Description |
248
+ | ------------------- | ------------- | ---------------------------------- |
249
+ | primaryColor | string | Primary brand color |
250
+ | secondaryColor | string | Secondary brand color |
251
+ | backgroundColor | string | Background color |
252
+ | textPrimaryColor | string | Primary text color |
253
+ | textSecondaryColor | string | Secondary text color |
254
+ | fontFamily | string | Font family |
255
+ | width | string/number | Component width in pixels |
256
+ | paddingWrapper | string/number | Padding for component wrapper |
257
+ | borderRadiusWrapper | string/number | Border radius for component wrapper|
193
258
 
194
259
  ## 🌐 Internationalization
195
260