@astropay/payments-lib 0.0.10 → 0.0.12

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
@@ -3,6 +3,7 @@
3
3
 
4
4
  ![AstroPay](https://getapp.astropay.com/img/astropay/2023/logo-black.svg)
5
5
  </a>
6
+
6
7
  </div>
7
8
 
8
9
  AstroPay's official frontend library that allows you to easily embed customizable and secure payment components into your website or e-commerce platform. It supports seamless international transactions, theming, localization, and real-time payment processing — all with minimal setup.
@@ -11,6 +12,7 @@ AstroPay's official frontend library that allows you to easily embed customizabl
11
12
 
12
13
  [![NPM version](https://img.shields.io/npm/v/@astropay/payments-lib/latest.svg)](https://www.npmjs.com/package/@astropay/payments-lib)
13
14
  [![NPM downloads](https://img.shields.io/npm/dm/@astropay/payments-lib.svg)](https://www.npmjs.com/package/@astropay/payments-lib)
15
+
14
16
  </div>
15
17
 
16
18
  ## 🚀 Quick Links
@@ -30,9 +32,12 @@ AstroPay's official frontend library that allows you to easily embed customizabl
30
32
  - [Yarn](#yarn)
31
33
  - [🚀 Basic Usage](#-basic-usage)
32
34
  - [🧩 Components](#-components)
33
- - [AstroPayPaymentComponent](#astropaypaymentcomponent)
35
+ - [AstroPayFullCheckout](#astropayfullcheckout)
34
36
  - [Props](#props)
35
37
  - [Example](#example)
38
+ - [AstroPayPayment](#astropaypayment)
39
+ - [Props](#props-1)
40
+ - [Example](#example-1)
36
41
  - [🎨 Styling \& Theming](#-styling--theming)
37
42
  - [Available Themes](#available-themes)
38
43
  - [Custom Styling](#custom-styling)
@@ -81,10 +86,10 @@ yarn add @astropay/payments-lib
81
86
  Initialize the library with your API token and optional configuration:
82
87
 
83
88
  ```typescript
84
- import AstroPayPaymentsLib, { AstroPayPaymentComponent } from '@astropay/payments-lib';
89
+ import AstroPayCore, { AstroPayFullCheckout } from '@astropay/payments-lib';
85
90
 
86
91
  // Initialize the library
87
- AstroPayPaymentsLib.init('app-id', {
92
+ AstroPayCore.init('app-id', {
88
93
  environment: 'production', // or 'sandbox'
89
94
  theme: 'light', // or 'dark'
90
95
  language: 'en', // or 'es', 'pt'
@@ -92,49 +97,109 @@ AstroPayPaymentsLib.init('app-id', {
92
97
  });
93
98
 
94
99
  // Use the payment component in your application
95
- // Note: Make sure an HTML element with id="payment-container" exists in your DOM before running this code
96
- const paymentElement = document.getElementById('payment-container');
97
- const payment = new AstroPayPaymentComponent({
100
+ const paymentComponent = new AstroPayFullCheckout({
98
101
  amount: 100,
99
102
  currency: 'USD',
100
103
  country: 'BR',
104
+ onSuccess: () => console.log('Payment successful'),
105
+ onError: () => console.error('Payment failed')
101
106
  });
102
107
 
103
- 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();
104
114
  ```
105
115
 
106
116
  ## 🧩 Components
107
117
 
108
- ### AstroPayPaymentComponent
118
+ ### AstroPayFullCheckout
109
119
 
110
120
  The main component for rendering a payment interface.
111
121
 
112
122
  #### Props
113
123
 
114
- | Prop | Type | Required | Description |
115
- |------|------|----------|-------------|
116
- | amount | number | Yes | The payment amount |
117
- | currency | string | Yes | The currency code (e.g., 'USD') |
118
- | country | string | Yes | The country code (e.g., 'BR', 'US') |
119
- | showTitle | boolean | No | Whether to show the component title (defaults to `true`) |
120
- | 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 |
121
133
 
122
134
  #### Example
123
135
 
124
136
  ```typescript
125
- import { AstroPayPaymentComponent } from '@astropay/payments-lib';
137
+ import { AstroPayFullCheckout } from '@astropay/payments-lib';
126
138
 
127
- const paymentComponent = new AstroPayPaymentComponent({
139
+ const fullCheckoutComponent = new AstroPayFullCheckout({
128
140
  amount: 100,
129
141
  currency: 'USD',
130
142
  country: 'US',
131
143
  // Optional props
132
144
  showTitle: true,
133
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
+ }
134
154
  });
135
155
 
136
- // Note: Make sure an HTML element with id="payment-container" exists in your DOM before running this code
137
- document.getElementById('payment-container').appendChild(paymentComponent.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();
138
203
  ```
139
204
 
140
205
  ## 🎨 Styling & Theming
@@ -151,7 +216,7 @@ The library comes with two built-in themes:
151
216
  You can specify the theme during initialization:
152
217
 
153
218
  ```typescript
154
- AstroPayPaymentsLib.init('app-id', {
219
+ AstroPayCore.init('app-id', {
155
220
  theme: 'dark',
156
221
  environment: 'production', // or 'sandbox'
157
222
  language: 'en',
@@ -164,7 +229,7 @@ AstroPayPaymentsLib.init('app-id', {
164
229
  You can customize the styling by providing a `styles` object in the initialization configuration:
165
230
 
166
231
  ```typescript
167
- AstroPayPaymentsLib.init('app-id', {
232
+ AstroPayCore.init('app-id', {
168
233
  styles: {
169
234
  primaryColor: '#FF5500',
170
235
  secondaryColor: '#00AAFF',
@@ -179,15 +244,17 @@ AstroPayPaymentsLib.init('app-id', {
179
244
 
180
245
  #### Available Style Properties
181
246
 
182
- | Property | Type | Description |
183
- |----------|------|-------------|
184
- | primaryColor | string | Primary brand color |
185
- | secondaryColor | string | Secondary brand color |
186
- | backgroundColor | string | Background color |
187
- | textPrimaryColor | string | Primary text color |
188
- | textSecondaryColor | string | Secondary text color |
189
- | fontFamily | string | Font family |
190
- | 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|
191
258
 
192
259
  ## 🌐 Internationalization
193
260
 
@@ -202,7 +269,7 @@ The library supports multiple languages through the i18next internationalization
202
269
  You can specify the language during initialization:
203
270
 
204
271
  ```typescript
205
- AstroPayPaymentsLib.init('app-id', {
272
+ AstroPayCore.init('app-id', {
206
273
  language: 'es',
207
274
  });
208
275
  ```