@verapay/verapay-js 1.0.1 → 1.2.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
@@ -20,19 +20,22 @@ npm install @verapay/verapay-js
20
20
 
21
21
  ## Quick Start
22
22
 
23
- Initialize the SDK with your `merchantId` and the payment details no backend setup required:
23
+ Partners should integrate once with a single publishable key and pass `merchantId` dynamically per transaction:
24
24
 
25
25
  ```typescript
26
26
  import { VerapayClient } from '@verapay/verapay-js';
27
27
 
28
28
  const verapay = new VerapayClient({
29
- merchantId: 'your-merchant-id',
30
- paymentData: { amount: 5000, currency: 'gbp' },
29
+ apiKey: 'vpy_pk_test_...', // partner publishable key
30
+ merchantId: currentMerchant.id, // dynamic per order
31
+ paymentData: { amount: order.total, currency: 'gbp' },
31
32
  });
32
33
 
33
34
  await verapay.mountPaymentForm('#payment-form');
34
35
  ```
35
36
 
37
+ For single-merchant integrations, pass a fixed merchant ID in the same config.
38
+
36
39
  Then process the payment when your form is submitted:
37
40
 
38
41
  ```typescript
@@ -47,6 +50,7 @@ const result = await verapay.processPayment({
47
50
  import { VerapayClient, ValidationError, PaymentError } from '@verapay/verapay-js';
48
51
 
49
52
  const verapay = new VerapayClient({
53
+ apiKey: 'vpy_pk_test_...',
50
54
  merchantId: 'your-merchant-id',
51
55
  paymentData: { amount: 5000, currency: 'gbp' },
52
56
  });
@@ -56,6 +60,7 @@ If your Merchant account is associated with a Partner, include `partnerFee` —
56
60
 
57
61
  ```typescript
58
62
  const verapay = new VerapayClient({
63
+ apiKey: 'vpy_pk_test_...',
59
64
  merchantId: 'your-merchant-id',
60
65
  paymentData: { amount: 5000, currency: 'gbp', partnerFee: 250 },
61
66
  });
@@ -77,22 +82,100 @@ try {
77
82
  }
78
83
  ```
79
84
 
80
- ## Dev/Local Environment
85
+ ## Test Mode
86
+
87
+ The SDK automatically detects the environment from your API key prefix — no flags needed:
88
+
89
+ | Key prefix | Backend | Stripe key |
90
+ |---|---|---|
91
+ | `vpy_pk_test_...` | `test-api.verapay.app` | Stripe **test** publishable key |
92
+ | `vpy_pk_live_...` | `api.verapay.app` | Stripe **live** publishable key |
81
93
 
82
- Set `enableTestMode: true` to point the SDK at the Verapay Staging backend and use Stripe's test publishable key no other configuration is needed:
94
+ Legacy `vpy_test_...` keys remain supported for backwards compatibility but are deprecated and will be removed in the next major release.
83
95
 
84
96
  ```typescript
97
+ // Test mode — inferred from the key
85
98
  const verapay = new VerapayClient({
99
+ apiKey: 'vpy_pk_test_...',
86
100
  merchantId: 'your-merchant-id',
87
101
  paymentData: { amount: 5000, currency: 'gbp' },
88
- enableTestMode: true,
89
102
  });
90
103
  ```
91
104
 
92
- When `enableTestMode` is enabled:
93
- - The SDK connects to a Verapay Test environment instead of the Production environment
94
- - Stripe is initialised with the Test publishable key, so no real charges are made
95
- - You will only be able to use Merchant IDs created in Test. Production Merchant IDs will not work here will cause errors.
105
+ When using a test key:
106
+ - The SDK connects to the Verapay Test environment
107
+ - Stripe is initialised with the Test publishable key no real charges are made
108
+ - You must use Merchant IDs created in the **Test** environment; attempting to access a live merchant with a test key returns a `403 Forbidden` error
109
+
110
+ ### Environment Mismatch
111
+
112
+ The backend strictly enforces environment isolation. If the key environment does not match the merchant or payment intent environment, the request is rejected:
113
+
114
+ ```typescript
115
+ try {
116
+ await verapay.initialize();
117
+ } catch (error) {
118
+ if (error instanceof PaymentError && error.details.code === 'FORBIDDEN') {
119
+ // Key environment does not match merchant environment
120
+ // Ensure your API key and merchantId are from the same environment
121
+ }
122
+ }
123
+ ```
124
+
125
+ **Common cause**: Using a `vpy_pk_test_...` key with a `merchantId` that was created in the live environment (or vice versa).
126
+
127
+ ## Going Live
128
+
129
+ To switch from test to live mode:
130
+
131
+ 1. Obtain a live publishable key from your Verapay dashboard (`vpy_pk_live_...`)
132
+ 2. Replace the `apiKey` in your config — no other code changes are needed:
133
+
134
+ ```typescript
135
+ // Before (test mode)
136
+ const verapay = new VerapayClient({
137
+ apiKey: 'vpy_pk_test_...',
138
+ merchantId: 'test-merchant-uuid',
139
+ paymentData: { amount: 5000, currency: 'gbp' },
140
+ });
141
+
142
+ // After (live mode)
143
+ const verapay = new VerapayClient({
144
+ apiKey: 'vpy_pk_live_...',
145
+ merchantId: 'live-merchant-uuid', // must be a live-environment merchant
146
+ paymentData: { amount: 5000, currency: 'gbp' },
147
+ });
148
+ ```
149
+
150
+ > **Merchant IDs are environment-specific.** You must obtain the corresponding live `merchantId` from your Verapay dashboard. A test `merchantId` will not work with a live key.
151
+
152
+ 3. Remove any `apiUrlOverride` from your config — the correct endpoint is automatically derived from the key prefix
153
+ 4. Ensure your backend has `STRIPE_PUBLISHABLE_KEY` (live) and `SANDBOX_STRIPE_PUBLISHABLE_KEY` (test) both configured
154
+
155
+ ### Partner Integration
156
+
157
+ Partners integrate with a single publishable key and pass `merchantId` dynamically per transaction:
158
+
159
+ ```typescript
160
+ const verapay = new VerapayClient({
161
+ apiKey: 'vpy_pk_test_...', // partner's publishable key
162
+ merchantId: currentMerchant.id, // set dynamically from your order logic
163
+ paymentData: { amount: order.total, currency: 'gbp' },
164
+ });
165
+ ```
166
+
167
+ ### Local Development
168
+
169
+ Use `apiUrlOverride` to point at a locally running backend:
170
+
171
+ ```typescript
172
+ const verapay = new VerapayClient({
173
+ apiKey: 'vpy_pk_test_...',
174
+ merchantId: 'your-merchant-id',
175
+ paymentData: { amount: 5000, currency: 'gbp' },
176
+ apiUrlOverride: 'http://localhost:8083',
177
+ });
178
+ ```
96
179
 
97
180
  ## Advanced Usage
98
181
 
@@ -108,6 +191,7 @@ Mount individual card elements for a custom layout:
108
191
 
109
192
  ```typescript
110
193
  const verapay = new VerapayClient({
194
+ apiKey: 'vpy_pk_test_...',
111
195
  merchantId: 'your-merchant-id',
112
196
  paymentData: { amount: 5000, currency: 'gbp' },
113
197
  });
@@ -134,6 +218,7 @@ When using `mountPaymentForm` or `mountAddress`, pass an `appearance` object to
134
218
 
135
219
  ```typescript
136
220
  const verapay = new VerapayClient({
221
+ apiKey: 'vpy_pk_test_...',
137
222
  merchantId: 'your-merchant-id',
138
223
  paymentData: { amount: 5000, currency: 'gbp' },
139
224
  appearance: {
@@ -156,6 +241,7 @@ The SDK ships with a default style for card fields that works out of the box —
156
241
 
157
242
  ```typescript
158
243
  const verapay = new VerapayClient({
244
+ apiKey: 'vpy_pk_test_...',
159
245
  merchantId: 'your-merchant-id',
160
246
  paymentData: { amount: 5000, currency: 'gbp' },
161
247
  // no elementsConfig needed — sensible defaults are applied automatically
@@ -168,6 +254,7 @@ Pass only the properties you want to change. Your values are merged with the def
168
254
 
169
255
  ```typescript
170
256
  const verapay = new VerapayClient({
257
+ apiKey: 'vpy_pk_test_...',
171
258
  merchantId: 'your-merchant-id',
172
259
  paymentData: { amount: 5000, currency: 'gbp' },
173
260
  elementsConfig: {
@@ -204,6 +291,7 @@ By default Stripe Elements renders in the browser's detected language. Pass `loc
204
291
 
205
292
  ```typescript
206
293
  const verapay = new VerapayClient({
294
+ apiKey: 'vpy_pk_test_...',
207
295
  merchantId: 'your-merchant-id',
208
296
  paymentData: { amount: 5000, currency: 'gbp' },
209
297
  locale: 'fr',
@@ -218,6 +306,7 @@ Stripe Elements run inside sandboxed iframes and cannot access fonts loaded on y
218
306
 
219
307
  ```typescript
220
308
  const verapay = new VerapayClient({
309
+ apiKey: 'vpy_pk_test_...',
221
310
  merchantId: 'your-merchant-id',
222
311
  paymentData: { amount: 5000, currency: 'gbp' },
223
312
  fonts: [
@@ -341,13 +430,14 @@ new VerapayClient(config: VerapayConfig)
341
430
 
342
431
  | Property | Type | Required | Description |
343
432
  |---|---|---|---|
344
- | `merchantId` | `string` | Yes | Your Merchant ID from onboarding |
433
+ | `apiKey` | `string` | Yes | Your Verapay publishable key (`vpy_pk_test_...` or `vpy_pk_live_...`). Environment is inferred from the prefix. |
434
+ | `merchantId` | `string` | No | Merchant ID. Required for single-merchant integrations. Partners pass this dynamically per transaction. |
345
435
  | `paymentData` | `PaymentData` | Yes | Amount, currency, and optional Partner fee |
346
436
  | `appearance` | `Appearance` | No | Styles `mountPaymentForm` and `mountAddress` elements |
347
437
  | `locale` | `StripeElementLocale` | No | Locale for Stripe Elements |
348
438
  | `fonts` | `StripeElementsOptions['fonts']` | No | Custom fonts for Stripe Elements |
349
439
  | `elementsConfig` | `ElementsConfig` | No | Styles `mountCardNumber`, `mountCardExpiry`, and `mountCardCvc` elements |
350
- | `enableTestMode` | `boolean` | No | Connects to the staging backend and uses Stripe's test key. For local development only — never use in production |
440
+ | `apiUrlOverride` | `string` | No | Override the backend URL. For local development only (e.g. `http://localhost:8083`) — never use in production. |
351
441
 
352
442
  #### PaymentData
353
443
 
package/dist/index.cjs CHANGED
@@ -1,3 +1,3 @@
1
- 'use strict';var stripeJs=require('@stripe/stripe-js'),tsMoney=require('ts-money');var i=class o extends Error{constructor(e,t="PAYMENT_FAILED",r){super(e),this.name="VerapayError",this.code=t,this.details={code:t,message:e,formattedMessage:this.formatMessage(e,t),...r},Error.captureStackTrace&&Error.captureStackTrace(this,o);}formatMessage(e,t){return {VALIDATION_ERROR:"Please check your payment information and try again.",PAYMENT_FAILED:"Your payment could not be processed. Please try again.",AUTHENTICATION_FAILED:"Payment authentication failed. Please try again.",NETWORK_ERROR:"Network error. Please check your connection and try again.",STRIPE_ERROR:"Payment service error. Please try again later.",CONFIGURATION_ERROR:"Configuration error. Please contact support.",CARD_DECLINED:"Your card was declined. Please use a different payment method.",INSUFFICIENT_FUNDS:"Insufficient funds. Please use a different payment method.",EXPIRED_CARD:"Your card has expired. Please use a different payment method."}[t]||e}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}};var m=class extends i{constructor(e,t,r){super(e,"VALIDATION_ERROR",{field:t,metadata:r}),this.name="ValidationError";}};var l=class o extends i{constructor(e,t,r){let n=o.mapStripeCode(t);super(e,n,{stripeCode:t,metadata:r}),this.name="PaymentError";}static mapStripeCode(e){return e?{card_declined:"CARD_DECLINED",insufficient_funds:"INSUFFICIENT_FUNDS",expired_card:"EXPIRED_CARD",incorrect_cvc:"VALIDATION_ERROR",processing_error:"PAYMENT_FAILED",authentication_failed:"AUTHENTICATION_FAILED"}[e]||"PAYMENT_FAILED":"PAYMENT_FAILED"}};var u=class{static formatForUser(e){return "formattedMessage"in e?e.formattedMessage:"details"in e&&e.details&&typeof e.details=="object"&&"formattedMessage"in e.details&&typeof e.details.formattedMessage=="string"?e.details.formattedMessage:"An unexpected error occurred. Please try again."}static formatForDeveloper(e){return "code"in e&&"message"in e?`[${e.code}] ${e.message}`:e.message||"Unknown error"}static toJSON(e){return "toJSON"in e&&typeof e.toJSON=="function"?e.toJSON():{name:e.name||"Error",message:e.message,..."code"in e&&{code:e.code},..."details"in e&&{details:e.details}}}};var E=class{constructor(e){this.stripe=e;}async confirmPayment(e,t){let r=await this.stripe.confirmPayment({clientSecret:t,confirmParams:{payment_method:e,return_url:window.location.href},redirect:"if_required"});if(r.error)throw new l(r.error.message||"Payment failed",r.error.code);return r}async confirmCardPayment(e,t){let r=await this.stripe.confirmCardPayment(t,{payment_method:e});if(r.error)throw new l(r.error.message||"Payment failed",r.error.code);return r}async createPaymentMethod(e,t=false){let r;if(!t)r=await this.stripe.createPaymentMethod({elements:e});else {let a=(await e.getElement("address",{mode:"billing"}).getValue()).value;r=await this.stripe.createPaymentMethod({type:"card",card:e.getElement("cardNumber"),billing_details:{name:a.name,address:{...a.address,line2:a.address.line2??void 0}}});}if(r.error||!r.paymentMethod)throw new l(r.error?.message||"Failed to create payment method",r.error?.code);return r.paymentMethod.id}};var d={showIcon:true,iconStyle:"solid",placeholders:{cardNumber:"1234 1234 1234 1234",cardExpiry:"MM / YY - TESTING",cardCvc:"CVC"},style:{base:{color:"#333333",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"16px","::placeholder":{color:"#aab7c4"}},complete:{color:"#333333"},empty:{},invalid:{color:"#df1b41"}}},v={cardNumber:"Card number",cardExpiry:"Expiry date",cardCvc:"CVC",address:"Address"},f=class{constructor(e,t,r){this.stripe=e;this.config=t;this.clientSecret=r;this.elements=null;this.mountedElements=new Map;this.elementStates=new Map;if(!r)throw new i("Client secret not initialized","CONFIGURATION_ERROR")}mountPaymentElement(e){if(!this.elements){let n={clientSecret:this.clientSecret,appearance:this.config.appearance,locale:this.config.locale,fonts:this.config.fonts,paymentMethodCreation:"manual"};this.elements=this.stripe.elements(n);}if(!document.querySelector(e))throw new i(`Element not found: ${e}`,"CONFIGURATION_ERROR");let r=this.elements.create("payment",{layout:"tabs",wallets:{link:"never"}});r.mount(e),this.mountedElements.set("payment",r);}mountCardNumberElement(e){this.mountIndividualFormElement(e,"cardNumber",this.cardElementOptions("cardNumber"));}mountCardExpiryElement(e){this.mountIndividualFormElement(e,"cardExpiry",this.cardElementOptions("cardExpiry"));}mountCardCvcElement(e){this.mountIndividualFormElement(e,"cardCvc",this.cardElementOptions("cardCvc"));}mountAddressElement(e,t){this.mountIndividualFormElement(e,"address",{mode:t});}cardElementOptions(e){let{elementsConfig:t}=this.config,r={placeholder:t?.placeholders?.[e]??d.placeholders[e],style:{base:{...d.style.base,...t?.style?.base},complete:{...d.style.complete,...t?.style?.complete},empty:{...d.style.empty,...t?.style?.empty},invalid:{...d.style.invalid,...t?.style?.invalid}}};return e==="cardNumber"&&(r.showIcon=t?.showIcon??d.showIcon,r.iconStyle=t?.iconStyle??d.iconStyle),r}mountIndividualFormElement(e,t,r){if(!document.querySelector(e))throw new i(`Element not found: ${e}`,"CONFIGURATION_ERROR");let a=this.createIndividualFormElement(t,r);a.mount(e),this.mountedElements.set(t,a),this.trackElementState(t,a);}createIndividualFormElement(e,t){return this.elements||(this.elements=this.stripe.elements({appearance:this.config.appearance,locale:this.config.locale,fonts:this.config.fonts,paymentMethodCreation:"manual"})),this.elements.create(e,t)}async validate(){let e=[];for(let[t,r]of this.elementStates.entries())r.complete||e.push({field:t,message:r.error??`${v[t]??t} failed validation`});return {isValid:e.length===0,errors:e}}getElements(){return this.elements}unmountAll(){for(let e of this.mountedElements.values())e.unmount();this.mountedElements.clear(),this.elementStates.clear();}trackElementState(e,t){this.elementStates.set(e,{complete:false});let r=n=>{this.elementStates.set(e,{complete:n.complete,error:n.error?.message});};t.on("change",r);}};var h=class{constructor(){this.extensions=[];}add(e){this.extensions.push(e);}async runBeforePayment(e){let t=e;for(let r of this.extensions)r.beforePayment&&(t=await r.beforePayment(t));return t}async runAfterPayment(e){await Promise.all(this.extensions.filter(t=>t.afterPayment).map(t=>t.afterPayment(e)));}async runOnError(e){await Promise.all(this.extensions.filter(t=>t.onPaymentError).map(t=>t.onPaymentError(e)));}};var g=class{constructor(e,t,r){this.stripeAdapter=e;this.elementsManager=t;this.verapayService=r;}async process(e,t){let r=this.elementsManager.getElements();await this.validatePaymentCanProceed(r,t),await r.submit();let n=await this.stripeAdapter.createPaymentMethod(r,t.isUsingIndividualFormElements);return await this.verapayService.processPrePayment({merchantId:t.merchantId,paymentIntentId:t.paymentIntentId,paymentMethodId:n,customerData:{email:e.customerEmail,firstName:e.customerFirstName,lastName:e.customerLastName},description:e.description,metadata:e.metadata}),this.confirmPayment(n,t)}async validatePaymentCanProceed(e,t){if(!e)throw new i("Payment form not mounted","CONFIGURATION_ERROR");if(t.isUsingStripePaymentElement&&t.isUsingIndividualFormElements)throw new i("Both forms of payment form in use");if(t.isUsingIndividualFormElements){let r=await this.elementsManager.validate();if(!r.isValid)throw new i(r.errors[0].message,"VALIDATION_ERROR")}}async confirmPayment(e,t){let{clientSecret:r,isUsingStripePaymentElement:n,isUsingIndividualFormElements:a}=t,s;return n?s=await this.stripeAdapter.confirmPayment(e,r):a&&(s=await this.stripeAdapter.confirmCardPayment(e,r)),this.formatPaymentResult(s)}formatPaymentResult(e){return {success:e.paymentIntent.status==="succeeded",paymentIntentId:e.paymentIntent.id,status:e.paymentIntent.status}}};var y=class{constructor(e){this.baseUrl=e;}async initialisePayment(e){let{merchantId:t,paymentData:r}=e;try{let n=await fetch(`${this.baseUrl}/api/initialise-payment`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":"example.api.key"},body:JSON.stringify({merchantId:t,paymentData:{...r,paymentMethodType:"card"}})});if(!n.ok){let s=await n.json().catch(()=>({}));throw new i(s.error||`HTTP error! status: ${n.status}`,"CONFIGURATION_ERROR")}let a=await n.json();if(!a.clientSecret||!a.paymentIntentId)throw new i("Missing clientSecret or paymentIntentId in server response","CONFIGURATION_ERROR");return {paymentIntentId:a.paymentIntentId,clientSecret:a.clientSecret,connectAccountId:a.connectAccountId}}catch(n){throw n instanceof i?n:new i(n instanceof Error?n.message:"Unknown error occurred","CONFIGURATION_ERROR")}}async processPrePayment(e){try{let t=await fetch(`${this.baseUrl}/api/process-prepayment`,{method:"POST",headers:{"Content-Type":"application/json","x-forwarded-for":"example.ip.addr"},body:JSON.stringify({merchantId:e.merchantId,paymentIntentId:e.paymentIntentId,paymentMethodId:e.paymentMethodId,customerData:e.customerData,description:e.description,metadata:e.metadata})});if(!t.ok){let r=await t.json().catch(()=>({}));throw new i(r.error||`HTTP error! status: ${t.status}`,"CONFIGURATION_ERROR")}}catch(t){throw t instanceof i?t:new i(t instanceof Error?t.message:"Unknown error occurred","CONFIGURATION_ERROR")}}};var c=class c{constructor(e){this.stripeAdapter=null;this.elementsManager=null;this.paymentService=null;this.isUsingStripePaymentElement=false;this.isUsingIndividualFormElements=false;this.clientSecret=null;this.paymentIntentId=null;this.config=e;let t=e.enableTestMode?c.BACKEND_URL_TEST_MODE:c.BACKEND_URL;this.verapayService=new y(t),this.extensionsManager=new h;}async initialize(){this.validatePaymentInitialisation();let{clientSecret:e,paymentIntentId:t}=await this.verapayService.initialisePayment({merchantId:this.config.merchantId,paymentData:this.config.paymentData});this.clientSecret=e,this.paymentIntentId=t;let r=this.config.enableTestMode?c.STRIPE_PUBLISHABLE_KEY_TEST_MODE:c.STRIPE_PUBLISHABLE_KEY,n=await stripeJs.loadStripe(r);if(!n)throw new i("Failed to load Stripe","CONFIGURATION_ERROR");this.stripeAdapter=new E(n),this.elementsManager=new f(n,this.config,e),this.paymentService=new g(this.stripeAdapter,this.elementsManager,this.verapayService);}async processPayment(e){await this.ensureInitialized();let t=await this.extensionsManager.runBeforePayment(e);try{let r=await this.paymentService.process(t,{merchantId:this.config.merchantId,paymentIntentId:this.paymentIntentId,clientSecret:this.clientSecret,isUsingStripePaymentElement:this.isUsingStripePaymentElement,isUsingIndividualFormElements:this.isUsingIndividualFormElements});return await this.extensionsManager.runAfterPayment(r),r}catch(r){throw await this.extensionsManager.runOnError(r),this.handlePaymentError(r)}}async mountPaymentForm(e){await this.ensureInitialized(),this.elementsManager.mountPaymentElement(e),this.isUsingStripePaymentElement=true;}async mountCardNumber(e){await this.ensureInitialized(),this.elementsManager.mountCardNumberElement(e),this.isUsingIndividualFormElements=true;}async mountCardExpiry(e){await this.ensureInitialized(),this.elementsManager.mountCardExpiryElement(e),this.isUsingIndividualFormElements=true;}async mountCardCvc(e){await this.ensureInitialized(),this.elementsManager.mountCardCvcElement(e),this.isUsingIndividualFormElements=true;}async mountAddress(e,t){await this.ensureInitialized(),this.elementsManager.mountAddressElement(e,t),this.isUsingIndividualFormElements=true;}addExtension(e){this.extensionsManager.add(e);}async ensureInitialized(){this.stripeAdapter||await this.initialize();}validatePaymentInitialisation(){let{amount:e,currency:t,partnerFee:r}=this.config.paymentData;if(!t)throw new m("Currency is required","currency");let n=t.toUpperCase(),a=this.toMoney(e,n,"amount");if(a.isZero()||a.isNegative())throw new m("Amount must be greater than 0","amount");if(r!==void 0){let s=this.toMoney(r,n,"partnerFee");if(s.isNegative())throw new m("partnerFee cannot be negative","partnerFee");if(s.greaterThan(a))throw new m("partnerFee cannot exceed the payment amount","partnerFee")}}toMoney(e,t,r){try{return tsMoney.Money.fromInteger(e,t)}catch{throw new m(`${r} must be an integer in the smallest currency unit (e.g., cents for USD)`,r)}}handlePaymentError(e){return e instanceof i?e:new l(e.message||"Payment failed",e.code)}};c.STRIPE_PUBLISHABLE_KEY="pk_live_51T04b5GzlW4meYBLBylH3vfoILSU2bGysbeqiG4bLajimWO4WRv1pROt7ZUhTwVqBXvwOCHBYFUtwnZ5ZgV9vBDT00IlUeRxax",c.STRIPE_PUBLISHABLE_KEY_TEST_MODE="pk_test_51TKE9hGhFtMLMQ7kOYMRzsV7kaQhyRNFO7KDNkSvtPSZClV67x9EJkmkEiWTUsjLpkBdRIx55568T5m28g50Mraj00nhMFqAIG",c.BACKEND_URL="https://api.verapay.app",c.BACKEND_URL_TEST_MODE="https://test-api.verapay.app";var R=c;var I=class{validateCardNumber(e){let t=e.replace(/\D/g,"");if(t.length<13||t.length>19)return false;let r=0,n=false;for(let a=t.length-1;a>=0;a--){let s=parseInt(t[a],10);n&&(s*=2,s>9&&(s-=9)),r+=s,n=!n;}return r%10===0}detectCardType(e){let t=e.replace(/\D/g,"");return /^4/.test(t)?"visa":/^5[1-5]/.test(t)?"mastercard":/^3[47]/.test(t)?"amex":/^6(?:011|5)/.test(t)?"discover":"unknown"}validateExpiry(e,t){let r=new Date,n=r.getFullYear(),a=r.getMonth()+1;if(e<1||e>12)return false;let s=t<100?2e3+t:t;return !(s<n||s===n&&e<a)}validateCVC(e,t="unknown"){let r=e.replace(/\D/g,"");return t==="amex"?r.length===4:r.length===3||r.length===4}validateAll(e,t,r,n){let a=this.detectCardType(e);return {number:{isValid:this.validateCardNumber(e),cardType:a},expiry:{isValid:this.validateExpiry(t,r),month:t,year:r},cvc:{isValid:this.validateCVC(n,a),length:n.replace(/\D/g,"").length}}}};var P=class{static sanitizeCardNumber(e){return e.replace(/\D/g,"")}static formatCardNumber(e){return this.sanitizeCardNumber(e).replace(/(\d{4})/g,"$1 ").trim()}static sanitizeCVC(e){return e.replace(/\D/g,"").slice(0,4)}static sanitizeExpiry(e){let t=e.replace(/\D/g,"");return t.length===4?{month:parseInt(t.slice(0,2),10),year:parseInt(t.slice(2,4),10)}:t.length===6?{month:parseInt(t.slice(0,2),10),year:parseInt(t.slice(2,6),10)}:null}};var ue="0.0.1";
2
- exports.CardValidator=I;exports.ErrorFormatter=u;exports.InputSanitizer=P;exports.PaymentError=l;exports.VERSION=ue;exports.ValidationError=m;exports.VerapayClient=R;exports.VerapayError=i;exports.VerapayService=y;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var stripeJs=require('@stripe/stripe-js'),tsMoney=require('ts-money');var i=class o extends Error{constructor(e,t="PAYMENT_FAILED",r){super(e),this.name="VerapayError",this.code=t,this.details={code:t,message:e,formattedMessage:this.formatMessage(e,t),...r},Error.captureStackTrace&&Error.captureStackTrace(this,o);}formatMessage(e,t){return {VALIDATION_ERROR:"Please check your payment information and try again.",PAYMENT_FAILED:"Your payment could not be processed. Please try again.",AUTHENTICATION_FAILED:"Payment authentication failed. Please try again.",NETWORK_ERROR:"Network error. Please check your connection and try again.",STRIPE_ERROR:"Payment service error. Please try again later.",CONFIGURATION_ERROR:"Configuration error. Please contact support.",CARD_DECLINED:"Your card was declined. Please use a different payment method.",INSUFFICIENT_FUNDS:"Insufficient funds. Please use a different payment method.",EXPIRED_CARD:"Your card has expired. Please use a different payment method."}[t]||e}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}};var m=class extends i{constructor(e,t,r){super(e,"VALIDATION_ERROR",{field:t,metadata:r}),this.name="ValidationError";}};var c=class o extends i{constructor(e,t,r){let n=o.mapStripeCode(t);super(e,n,{stripeCode:t,metadata:r}),this.name="PaymentError";}static mapStripeCode(e){return e?{card_declined:"CARD_DECLINED",insufficient_funds:"INSUFFICIENT_FUNDS",expired_card:"EXPIRED_CARD",incorrect_cvc:"VALIDATION_ERROR",processing_error:"PAYMENT_FAILED",authentication_failed:"AUTHENTICATION_FAILED"}[e]||"PAYMENT_FAILED":"PAYMENT_FAILED"}};var u=class{static formatForUser(e){return "formattedMessage"in e?e.formattedMessage:"details"in e&&e.details&&typeof e.details=="object"&&"formattedMessage"in e.details&&typeof e.details.formattedMessage=="string"?e.details.formattedMessage:"An unexpected error occurred. Please try again."}static formatForDeveloper(e){return "code"in e&&"message"in e?`[${e.code}] ${e.message}`:e.message||"Unknown error"}static toJSON(e){return "toJSON"in e&&typeof e.toJSON=="function"?e.toJSON():{name:e.name||"Error",message:e.message,..."code"in e&&{code:e.code},..."details"in e&&{details:e.details}}}};var h=class{constructor(e){this.stripe=e;}async confirmPayment(e,t){let r=await this.stripe.confirmPayment({clientSecret:t,confirmParams:{payment_method:e,return_url:window.location.href},redirect:"if_required"});if(r.error)throw new c(r.error.message||"Payment failed",r.error.code);return r}async confirmCardPayment(e,t){let r=await this.stripe.confirmCardPayment(t,{payment_method:e});if(r.error)throw new c(r.error.message||"Payment failed",r.error.code);return r}async createPaymentMethod(e,t=false){let r;if(!t)r=await this.stripe.createPaymentMethod({elements:e});else {let a=(await e.getElement("address",{mode:"billing"}).getValue()).value;r=await this.stripe.createPaymentMethod({type:"card",card:e.getElement("cardNumber"),billing_details:{name:a.name,address:{...a.address,line2:a.address.line2??void 0}}});}if(r.error||!r.paymentMethod)throw new c(r.error?.message||"Failed to create payment method",r.error?.code);return r.paymentMethod.id}};var p={showIcon:true,iconStyle:"solid",placeholders:{cardNumber:"1234 1234 1234 1234",cardExpiry:"MM / YY - TESTING",cardCvc:"CVC"},style:{base:{color:"#333333",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"16px","::placeholder":{color:"#aab7c4"}},complete:{color:"#333333"},empty:{},invalid:{color:"#df1b41"}}},v={cardNumber:"Card number",cardExpiry:"Expiry date",cardCvc:"CVC",address:"Address"},g=class{constructor(e,t,r){this.stripe=e;this.config=t;this.clientSecret=r;this.elements=null;this.mountedElements=new Map;this.elementStates=new Map;if(!r)throw new i("Client secret not initialized","CONFIGURATION_ERROR")}mountPaymentElement(e){if(!this.elements){let n={clientSecret:this.clientSecret,appearance:this.config.appearance,locale:this.config.locale,fonts:this.config.fonts,paymentMethodCreation:"manual"};this.elements=this.stripe.elements(n);}if(!document.querySelector(e))throw new i(`Element not found: ${e}`,"CONFIGURATION_ERROR");let r=this.elements.create("payment",{layout:"tabs",wallets:{link:"never"}});r.mount(e),this.mountedElements.set("payment",r);}mountCardNumberElement(e){this.mountIndividualFormElement(e,"cardNumber",this.cardElementOptions("cardNumber"));}mountCardExpiryElement(e){this.mountIndividualFormElement(e,"cardExpiry",this.cardElementOptions("cardExpiry"));}mountCardCvcElement(e){this.mountIndividualFormElement(e,"cardCvc",this.cardElementOptions("cardCvc"));}mountAddressElement(e,t){this.mountIndividualFormElement(e,"address",{mode:t});}cardElementOptions(e){let{elementsConfig:t}=this.config,r={placeholder:t?.placeholders?.[e]??p.placeholders[e],style:{base:{...p.style.base,...t?.style?.base},complete:{...p.style.complete,...t?.style?.complete},empty:{...p.style.empty,...t?.style?.empty},invalid:{...p.style.invalid,...t?.style?.invalid}}};return e==="cardNumber"&&(r.showIcon=t?.showIcon??p.showIcon,r.iconStyle=t?.iconStyle??p.iconStyle),r}mountIndividualFormElement(e,t,r){if(!document.querySelector(e))throw new i(`Element not found: ${e}`,"CONFIGURATION_ERROR");let a=this.createIndividualFormElement(t,r);a.mount(e),this.mountedElements.set(t,a),this.trackElementState(t,a);}createIndividualFormElement(e,t){return this.elements||(this.elements=this.stripe.elements({appearance:this.config.appearance,locale:this.config.locale,fonts:this.config.fonts,paymentMethodCreation:"manual"})),this.elements.create(e,t)}async validate(){let e=[];for(let[t,r]of this.elementStates.entries())r.complete||e.push({field:t,message:r.error??`${v[t]??t} failed validation`});return {isValid:e.length===0,errors:e}}getElements(){return this.elements}unmountAll(){for(let e of this.mountedElements.values())e.unmount();this.mountedElements.clear(),this.elementStates.clear();}trackElementState(e,t){this.elementStates.set(e,{complete:false});let r=n=>{this.elementStates.set(e,{complete:n.complete,error:n.error?.message});};t.on("change",r);}};var f=class{constructor(){this.extensions=[];}add(e){this.extensions.push(e);}async runBeforePayment(e){let t=e;for(let r of this.extensions)r.beforePayment&&(t=await r.beforePayment(t));return t}async runAfterPayment(e){await Promise.all(this.extensions.filter(t=>t.afterPayment).map(t=>t.afterPayment(e)));}async runOnError(e){await Promise.all(this.extensions.filter(t=>t.onPaymentError).map(t=>t.onPaymentError(e)));}};var E=class{constructor(e,t,r){this.stripeAdapter=e;this.elementsManager=t;this.verapayService=r;}async process(e,t){let r=this.elementsManager.getElements();await this.validatePaymentCanProceed(r,t),await r.submit();let n=await this.stripeAdapter.createPaymentMethod(r,t.isUsingIndividualFormElements);return await this.verapayService.processPrePayment({merchantId:t.merchantId,paymentIntentId:t.paymentIntentId,paymentMethodId:n,amount:t.amount,currency:t.currency,customerData:{email:e.customerEmail,firstName:e.customerFirstName,lastName:e.customerLastName},description:e.description,metadata:e.metadata}),this.confirmPayment(n,t)}async validatePaymentCanProceed(e,t){if(!e)throw new i("Payment form not mounted","CONFIGURATION_ERROR");if(t.isUsingStripePaymentElement&&t.isUsingIndividualFormElements)throw new i("Both forms of payment form in use");if(t.isUsingIndividualFormElements){let r=await this.elementsManager.validate();if(!r.isValid)throw new i(r.errors[0].message,"VALIDATION_ERROR")}}async confirmPayment(e,t){let{clientSecret:r,isUsingStripePaymentElement:n,isUsingIndividualFormElements:a}=t,s;return n?s=await this.stripeAdapter.confirmPayment(e,r):a&&(s=await this.stripeAdapter.confirmCardPayment(e,r)),this.formatPaymentResult(s)}formatPaymentResult(e){return {success:e.paymentIntent.status==="succeeded",paymentIntentId:e.paymentIntent.id,status:e.paymentIntent.status}}};var y=class{constructor(e,t){this.baseUrl=e,this.apiKey=t;}async initialisePayment(e){let{merchantId:t,paymentData:r}=e;try{let n=await fetch(`${this.baseUrl}/api/initialise-payment`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify({merchantId:t,paymentData:{...r,paymentMethodType:"card"}})});if(!n.ok){let s=await n.json().catch(()=>({}));throw new i(this.extractErrorMessage(s,n.status),"CONFIGURATION_ERROR")}let a=await n.json();if(!a.clientSecret||!a.paymentIntentId)throw new i("Missing clientSecret or paymentIntentId in server response","CONFIGURATION_ERROR");return {paymentIntentId:a.paymentIntentId,clientSecret:a.clientSecret,connectAccountId:a.connectAccountId,stripePublishableKey:a.stripePublishableKey}}catch(n){throw n instanceof i?n:new i(n instanceof Error?n.message:"Unknown error occurred","CONFIGURATION_ERROR")}}async processPrePayment(e){try{let t=await fetch(`${this.baseUrl}/api/process-prepayment`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify({merchantId:e.merchantId,paymentIntentId:e.paymentIntentId,paymentMethodId:e.paymentMethodId,amount:e.amount,currency:e.currency,customerData:e.customerData,description:e.description,metadata:e.metadata})});if(!t.ok){let r=await t.json().catch(()=>({}));throw new i(this.extractErrorMessage(r,t.status),"CONFIGURATION_ERROR")}}catch(t){throw t instanceof i?t:new i(t instanceof Error?t.message:"Unknown error occurred","CONFIGURATION_ERROR")}}extractErrorMessage(e,t){if(!e||typeof e!="object")return `HTTP error! status: ${t}`;let r=e,n=[r.error,r.message,r.details];for(let a of n){if(typeof a=="string"&&a.trim().length>0)return a;if(a&&typeof a=="object")try{return JSON.stringify(a)}catch{}}return `HTTP error! status: ${t}`}};var d=class d{constructor(e){this.stripeAdapter=null;this.elementsManager=null;this.paymentService=null;this.isUsingStripePaymentElement=false;this.isUsingIndividualFormElements=false;this.clientSecret=null;this.paymentIntentId=null;if(!e.apiKey)throw new i("apiKey is required. Pass your Verapay publishable key (vpy_pk_test_... or vpy_pk_live_...) when constructing VerapayClient.","CONFIGURATION_ERROR");this.config=e,!this.config.apiKey.includes("_pk_")&&typeof window<"u"&&console.warn("Verapay Security Warning: You are using a Secret Key in a frontend environment. Please use a Publishable Key (vpy_pk_...) instead.");let t=this.config.apiUrlOverride||(this.isTestKey()?d.BACKEND_URL_TEST_MODE:d.BACKEND_URL);this.verapayService=new y(t,this.config.apiKey),this.extensionsManager=new f;}async initialize(){this.validatePaymentInitialisation();let{clientSecret:e,paymentIntentId:t,stripePublishableKey:r}=await this.verapayService.initialisePayment({merchantId:this.config.merchantId??"",paymentData:this.config.paymentData});this.clientSecret=e,this.paymentIntentId=t;let n=await stripeJs.loadStripe(r);if(!n)throw new i("Failed to load Stripe","CONFIGURATION_ERROR");this.stripeAdapter=new h(n),this.elementsManager=new g(n,this.config,e),this.paymentService=new E(this.stripeAdapter,this.elementsManager,this.verapayService);}async processPayment(e){await this.ensureInitialized();let t=await this.extensionsManager.runBeforePayment(e);try{let r=await this.paymentService.process(t,{merchantId:this.config.merchantId??"",paymentIntentId:this.paymentIntentId,clientSecret:this.clientSecret,amount:this.config.paymentData.amount,currency:this.config.paymentData.currency,isUsingStripePaymentElement:this.isUsingStripePaymentElement,isUsingIndividualFormElements:this.isUsingIndividualFormElements});return await this.extensionsManager.runAfterPayment(r),r}catch(r){throw await this.extensionsManager.runOnError(r),this.handlePaymentError(r)}}async mountPaymentForm(e){await this.ensureInitialized(),this.elementsManager.mountPaymentElement(e),this.isUsingStripePaymentElement=true;}async mountCardNumber(e){await this.ensureInitialized(),this.elementsManager.mountCardNumberElement(e),this.isUsingIndividualFormElements=true;}async mountCardExpiry(e){await this.ensureInitialized(),this.elementsManager.mountCardExpiryElement(e),this.isUsingIndividualFormElements=true;}async mountCardCvc(e){await this.ensureInitialized(),this.elementsManager.mountCardCvcElement(e),this.isUsingIndividualFormElements=true;}async mountAddress(e,t){await this.ensureInitialized(),this.elementsManager.mountAddressElement(e,t),this.isUsingIndividualFormElements=true;}addExtension(e){this.extensionsManager.add(e);}async ensureInitialized(){this.stripeAdapter||await this.initialize();}validatePaymentInitialisation(){let{amount:e,currency:t,partnerFee:r}=this.config.paymentData;if(!t)throw new m("Currency is required","currency");let n=t.toUpperCase(),a=this.toMoney(e,n,"amount");if(a.isZero()||a.isNegative())throw new m("Amount must be greater than 0","amount");if(r!==void 0){let s=this.toMoney(r,n,"partnerFee");if(s.isNegative())throw new m("partnerFee cannot be negative","partnerFee");if(s.greaterThan(a))throw new m("partnerFee cannot exceed the payment amount","partnerFee")}}toMoney(e,t,r){try{return tsMoney.Money.fromInteger(e,t)}catch{throw new m(`${r} must be an integer in the smallest currency unit (e.g., cents for USD)`,r)}}isTestKey(){return this.config.apiKey.startsWith("vpy_pk_test_")||this.config.apiKey.startsWith("vpy_test_")}handlePaymentError(e){return e instanceof i?e:new c(e.message||"Payment failed",e.code)}};d.BACKEND_URL="https://api.verapay.app",d.BACKEND_URL_TEST_MODE="https://test-api.verapay.app";var R=d;var I=class{validateCardNumber(e){let t=e.replace(/\D/g,"");if(t.length<13||t.length>19)return false;let r=0,n=false;for(let a=t.length-1;a>=0;a--){let s=parseInt(t[a],10);n&&(s*=2,s>9&&(s-=9)),r+=s,n=!n;}return r%10===0}detectCardType(e){let t=e.replace(/\D/g,"");return /^4/.test(t)?"visa":/^5[1-5]/.test(t)?"mastercard":/^3[47]/.test(t)?"amex":/^6(?:011|5)/.test(t)?"discover":"unknown"}validateExpiry(e,t){let r=new Date,n=r.getFullYear(),a=r.getMonth()+1;if(e<1||e>12)return false;let s=t<100?2e3+t:t;return !(s<n||s===n&&e<a)}validateCVC(e,t="unknown"){let r=e.replace(/\D/g,"");return t==="amex"?r.length===4:r.length===3||r.length===4}validateAll(e,t,r,n){let a=this.detectCardType(e);return {number:{isValid:this.validateCardNumber(e),cardType:a},expiry:{isValid:this.validateExpiry(t,r),month:t,year:r},cvc:{isValid:this.validateCVC(n,a),length:n.replace(/\D/g,"").length}}}};var P=class{static sanitizeCardNumber(e){return e.replace(/\D/g,"")}static formatCardNumber(e){return this.sanitizeCardNumber(e).replace(/(\d{4})/g,"$1 ").trim()}static sanitizeCVC(e){return e.replace(/\D/g,"").slice(0,4)}static sanitizeExpiry(e){let t=e.replace(/\D/g,"");return t.length===4?{month:parseInt(t.slice(0,2),10),year:parseInt(t.slice(2,4),10)}:t.length===6?{month:parseInt(t.slice(0,2),10),year:parseInt(t.slice(2,6),10)}:null}};var ue="1.1.0";
2
+ exports.CardValidator=I;exports.ErrorFormatter=u;exports.InputSanitizer=P;exports.PaymentError=c;exports.VERSION=ue;exports.ValidationError=m;exports.VerapayClient=R;exports.VerapayError=i;exports.VerapayService=y;//# sourceMappingURL=index.cjs.map
3
3
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors/verapay-error.ts","../src/errors/validation-error.ts","../src/errors/payment-error.ts","../src/errors/error-formatter.ts","../src/client/stripe-adapter.ts","../src/client/elements-manager.ts","../src/client/payment-extensions-manager.ts","../src/services/payment-service.ts","../src/services/verapay-service.ts","../src/client/verapay-client.ts","../src/validation/card-validator.ts","../src/validation/input-sanitizer.ts","../src/index.ts"],"names":["VerapayError","_VerapayError","message","code","details","ValidationError","field","metadata","PaymentError","_PaymentError","stripeCode","ErrorFormatter","error","StripeAdapter","stripe","paymentMethodId","clientSecret","result","elements","isUsingIndividualFormElements","address","DEFAULT_CARD_ELEMENT_CONFIG","FIELD_LABELS","ElementsManager","config","selector","elementsConfig","element","mode","fieldType","options","formFieldType","errors","state","handleElementChange","event","PaymentExtensionsManager","extension","request","modifiedRequest","ext","PaymentService","stripeAdapter","elementsManager","verapayService","context","validation","isUsingStripePaymentElement","VerapayService","baseUrl","merchantId","paymentData","response","errorData","data","_VerapayClient","backendUrl","paymentIntentId","stripeKey","loadStripe","paymentResult","amount","currency","partnerFee","uppercaseCurrency","paymentAmount","partnerFeeAmount","value","fieldName","Money","VerapayClient","CardValidator","cardNumber","cleaned","sum","isEven","i","digit","month","year","now","currentYear","currentMonth","fullYear","cvc","cardType","expiryMonth","expiryYear","InputSanitizer","input","VERSION"],"mappings":"mFAGO,IAAMA,CAAAA,CAAN,MAAMC,CAAAA,SAAqB,KAAM,CAItC,WAAA,CACEC,CAAAA,CACAC,CAAAA,CAAAA,gBAAAA,CACAC,CAAAA,CACA,CACA,KAAA,CAAMF,CAAO,CAAA,CACb,IAAA,CAAK,IAAA,CAAO,cAAA,CACZ,IAAA,CAAK,IAAA,CAAOC,CAAAA,CACZ,IAAA,CAAK,OAAA,CAAU,CACb,IAAA,CAAAA,CAAAA,CACA,OAAA,CAAAD,CAAAA,CACA,gBAAA,CAAkB,IAAA,CAAK,aAAA,CAAcA,CAAAA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MAC5C,CAEA,OAAO,WAAA,CAAYA,CAAAA,CAAuB,CACxC,OAAOA,CAAAA,CAAM,QAAQ,KAAA,CAAO,EAAE,CAAA,CAAE,KAAA,CAAM,CAAA,CAAG,CAAC,CAC5C,CAEA,OAAO,cAAA,CAAeA,CAAAA,CAAuD,CAC3E,IAAMhB,CAAAA,CAAUgB,CAAAA,CAAM,OAAA,CAAQ,MAAO,EAAE,CAAA,CAEvC,OAAIhB,CAAAA,CAAQ,MAAA,GAAW,CAAA,CACd,CACL,KAAA,CAAO,SAASA,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,CAAA,CACvC,IAAA,CAAM,SAASA,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,CACxC,CAAA,CACSA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CACrB,CACL,KAAA,CAAO,QAAA,CAASA,CAAAA,CAAQ,KAAA,CAAM,EAAG,CAAC,CAAA,CAAG,EAAE,CAAA,CACvC,IAAA,CAAM,QAAA,CAASA,CAAAA,CAAQ,KAAA,CAAM,EAAG,CAAC,CAAA,CAAG,EAAE,CACxC,CAAA,CAGK,IACT,CACF,MCGaiB,EAAAA,CAAU","file":"index.cjs","sourcesContent":["import type { ErrorDetails } from '../types';\nimport { ErrorCode } from '../types';\n\nexport class VerapayError extends Error {\n public readonly code: ErrorCode;\n public readonly details: ErrorDetails;\n\n constructor(\n message: string,\n code: ErrorCode = ErrorCode.PAYMENT_FAILED,\n details?: Partial<ErrorDetails>\n ) {\n super(message);\n this.name = 'VerapayError';\n this.code = code;\n this.details = {\n code,\n message,\n formattedMessage: this.formatMessage(message, code),\n ...details,\n };\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, VerapayError);\n }\n }\n\n private formatMessage(message: string, code: ErrorCode): string {\n const messageMap: Record<ErrorCode, string> = {\n [ErrorCode.VALIDATION_ERROR]:\n 'Please check your payment information and try again.',\n [ErrorCode.PAYMENT_FAILED]:\n 'Your payment could not be processed. Please try again.',\n [ErrorCode.AUTHENTICATION_FAILED]:\n 'Payment authentication failed. Please try again.',\n [ErrorCode.NETWORK_ERROR]:\n 'Network error. Please check your connection and try again.',\n [ErrorCode.STRIPE_ERROR]:\n 'Payment service error. Please try again later.',\n [ErrorCode.CONFIGURATION_ERROR]:\n 'Configuration error. Please contact support.',\n [ErrorCode.CARD_DECLINED]:\n 'Your card was declined. Please use a different payment method.',\n [ErrorCode.INSUFFICIENT_FUNDS]:\n 'Insufficient funds. Please use a different payment method.',\n [ErrorCode.EXPIRED_CARD]:\n 'Your card has expired. Please use a different payment method.',\n };\n\n return messageMap[code] || message;\n }\n\n toJSON() {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n details: this.details,\n };\n }\n}\n","import { VerapayError } from './verapay-error';\nimport { ErrorCode } from '../types';\n\nexport class ValidationError extends VerapayError {\n constructor(message: string, field?: string, metadata?: Record<string, any>) {\n super(message, ErrorCode.VALIDATION_ERROR, {\n field,\n metadata,\n });\n this.name = 'ValidationError';\n }\n}\n","import { VerapayError } from './verapay-error';\nimport { ErrorCode } from '../types';\n\nexport class PaymentError extends VerapayError {\n constructor(\n message: string,\n stripeCode?: string,\n metadata?: Record<string, any>\n ) {\n const code = PaymentError.mapStripeCode(stripeCode);\n super(message, code, {\n stripeCode,\n metadata,\n });\n this.name = 'PaymentError';\n }\n\n private static mapStripeCode(stripeCode?: string): ErrorCode {\n if (!stripeCode) return ErrorCode.PAYMENT_FAILED;\n\n const codeMap: Record<string, ErrorCode> = {\n card_declined: ErrorCode.CARD_DECLINED,\n insufficient_funds: ErrorCode.INSUFFICIENT_FUNDS,\n expired_card: ErrorCode.EXPIRED_CARD,\n incorrect_cvc: ErrorCode.VALIDATION_ERROR,\n processing_error: ErrorCode.PAYMENT_FAILED,\n authentication_failed: ErrorCode.AUTHENTICATION_FAILED,\n };\n\n return codeMap[stripeCode] || ErrorCode.PAYMENT_FAILED;\n }\n}\n","import type { ErrorDetails } from '../types';\n\nexport class ErrorFormatter {\n static formatForUser(error: Error | ErrorDetails): string {\n if ('formattedMessage' in error) {\n return error.formattedMessage;\n }\n if (\n 'details' in error &&\n error.details &&\n typeof error.details === 'object' &&\n 'formattedMessage' in error.details &&\n typeof error.details.formattedMessage === 'string'\n ) {\n return error.details.formattedMessage;\n }\n return 'An unexpected error occurred. Please try again.';\n }\n\n static formatForDeveloper(error: Error | ErrorDetails): string {\n if ('code' in error && 'message' in error) {\n return `[${error.code}] ${error.message}`;\n }\n return error.message || 'Unknown error';\n }\n\n static toJSON(error: Error | ErrorDetails): Record<string, any> {\n if ('toJSON' in error && typeof error.toJSON === 'function') {\n return error.toJSON();\n }\n\n return {\n name: (error as Error).name || 'Error',\n message: error.message,\n ...('code' in error && { code: error.code }),\n ...('details' in error && { details: error.details }),\n };\n }\n}\n","import type { PaymentIntent, Stripe, StripeElements } from '@stripe/stripe-js';\nimport { PaymentError } from '../errors';\n\nexport class StripeAdapter {\n constructor(private stripe: Stripe) {}\n\n async confirmPayment(\n paymentMethodId: string,\n clientSecret: string\n ): Promise<{ paymentIntent: PaymentIntent }> {\n const result = await this.stripe.confirmPayment({\n clientSecret,\n confirmParams: {\n payment_method: paymentMethodId,\n return_url: window.location.href,\n },\n redirect: 'if_required',\n });\n\n if (result.error) {\n throw new PaymentError(\n result.error.message || 'Payment failed',\n result.error.code\n );\n }\n\n return result as { paymentIntent: PaymentIntent };\n }\n\n async confirmCardPayment(\n paymentMethodId: string,\n clientSecret: string\n ): Promise<{ paymentIntent: PaymentIntent }> {\n const result = await this.stripe.confirmCardPayment(clientSecret, {\n payment_method: paymentMethodId,\n });\n\n if (result.error) {\n throw new PaymentError(\n result.error.message || 'Payment failed',\n result.error.code\n );\n }\n\n return result as { paymentIntent: PaymentIntent };\n }\n\n async createPaymentMethod(\n elements: StripeElements,\n isUsingIndividualFormElements: boolean = false\n ): Promise<string> {\n let result;\n\n if (!isUsingIndividualFormElements) {\n result = await this.stripe.createPaymentMethod({\n elements,\n });\n } else {\n // @ts-ignore - Stripe types don't include mode parameter for getElement\n const addressElement = await elements.getElement('address', { mode: 'billing' })!.getValue();\n const address = addressElement!.value;\n\n result = await this.stripe.createPaymentMethod({\n type: 'card',\n card: elements.getElement('cardNumber')!,\n billing_details: {\n name: address.name,\n address: {\n ...address.address,\n line2: address.address.line2 ?? undefined,\n },\n },\n });\n }\n\n if (result.error || !result.paymentMethod) {\n throw new PaymentError(\n result.error?.message || 'Failed to create payment method',\n result.error?.code\n );\n }\n\n return result.paymentMethod.id;\n }\n}\n","import type {\n Stripe,\n StripeElements,\n StripeElement,\n StripePaymentElement,\n StripeCardNumberElement,\n PaymentWalletsOption,\n} from '@stripe/stripe-js';\nimport type { VerapayConfig, ValidationError, ValidationResult } from '../types';\nimport { VerapayError, ErrorCode } from '../errors';\n\ntype ElementState = { complete: boolean; error?: string }\n\nconst DEFAULT_CARD_ELEMENT_CONFIG = {\n showIcon: true,\n iconStyle: 'solid' as const,\n placeholders: {\n cardNumber: '1234 1234 1234 1234',\n cardExpiry: 'MM / YY - TESTING',\n cardCvc: 'CVC',\n },\n style: {\n base: {\n color: '#333333',\n fontFamily: 'system-ui, -apple-system, sans-serif',\n fontSize: '16px',\n '::placeholder': { color: '#aab7c4' },\n },\n complete: {\n color: '#333333',\n },\n empty: {},\n invalid: {\n color: '#df1b41',\n },\n },\n}\n\nconst FIELD_LABELS: Record<string, string> = {\n cardNumber: 'Card number',\n cardExpiry: 'Expiry date',\n cardCvc: 'CVC',\n address: 'Address',\n}\n\nexport class ElementsManager {\n private elements: StripeElements | null = null;\n private mountedElements: Map<string, StripeElement> = new Map();\n private elementStates: Map<string, ElementState> = new Map();\n\n constructor(\n private stripe: Stripe,\n private config: VerapayConfig,\n private clientSecret: string\n ) {\n if (!clientSecret) {\n throw new VerapayError(\n 'Client secret not initialized',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n mountPaymentElement(selector: string): void {\n if (!this.elements) {\n const elementsConfig = {\n clientSecret: this.clientSecret,\n appearance: this.config.appearance,\n locale: this.config.locale,\n fonts: this.config.fonts,\n paymentMethodCreation: 'manual',\n };\n\n this.elements = this.stripe.elements(elementsConfig);\n }\n\n const container = document.querySelector(selector);\n\n if (!container) {\n throw new VerapayError(\n `Element not found: ${selector}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const element = this.elements.create('payment', {\n layout: 'tabs',\n wallets: { link: 'never' } as unknown as PaymentWalletsOption,\n }) as StripePaymentElement;\n\n element.mount(selector);\n this.mountedElements.set('payment', element);\n }\n\n mountCardNumberElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardNumber', this.cardElementOptions('cardNumber'));\n }\n\n mountCardExpiryElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardExpiry', this.cardElementOptions('cardExpiry'));\n }\n\n mountCardCvcElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardCvc', this.cardElementOptions('cardCvc'));\n }\n\n mountAddressElement(selector: string, mode: 'billing' | 'shipping'): void {\n this.mountIndividualFormElement(selector, 'address', { mode });\n }\n\n private cardElementOptions(fieldType: 'cardNumber' | 'cardExpiry' | 'cardCvc'): Record<string, unknown> {\n const { elementsConfig } = this.config;\n const options: Record<string, unknown> = {\n placeholder: elementsConfig?.placeholders?.[fieldType] ?? DEFAULT_CARD_ELEMENT_CONFIG.placeholders[fieldType],\n style: {\n base: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.base, ...elementsConfig?.style?.base },\n complete: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.complete, ...elementsConfig?.style?.complete },\n empty: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.empty, ...elementsConfig?.style?.empty },\n invalid: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.invalid, ...elementsConfig?.style?.invalid },\n },\n };\n\n if (fieldType === 'cardNumber') {\n options.showIcon = elementsConfig?.showIcon ?? DEFAULT_CARD_ELEMENT_CONFIG.showIcon;\n options.iconStyle = elementsConfig?.iconStyle ?? DEFAULT_CARD_ELEMENT_CONFIG.iconStyle;\n }\n\n return options;\n }\n\n private mountIndividualFormElement(selector: string, formFieldType: 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address', options?: Record<string, unknown>) {\n const container = document.querySelector(selector);\n\n if (!container) {\n throw new VerapayError(\n `Element not found: ${selector}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const element = this.createIndividualFormElement(formFieldType, options) as StripeCardNumberElement;\n element.mount(selector);\n\n this.mountedElements.set(formFieldType, element);\n this.trackElementState(formFieldType, element);\n }\n\n private createIndividualFormElement(\n formFieldType: any,\n options?: Record<string, unknown>\n ): StripeElement {\n if (!this.elements) {\n // For individual card elements, don't pass clientSecret\n // It's only needed when creating Payment Element or confirming payment\n this.elements = this.stripe.elements({\n appearance: this.config.appearance,\n locale: this.config.locale,\n fonts: this.config.fonts,\n paymentMethodCreation: 'manual',\n });\n }\n\n return this.elements.create(formFieldType, options);\n }\n\n async validate(): Promise<ValidationResult> {\n const errors: ValidationError[] = []\n\n for (const [field, state] of this.elementStates.entries()) {\n if (!state.complete) {\n errors.push({\n field,\n message: state.error ?? `${FIELD_LABELS[field] ?? field} failed validation`,\n })\n }\n }\n\n return { isValid: errors.length === 0, errors }\n }\n\n getElements(): StripeElements | null {\n return this.elements;\n }\n\n unmountAll(): void {\n for (const element of this.mountedElements.values()) {\n element.unmount();\n }\n this.mountedElements.clear();\n this.elementStates.clear();\n }\n\n private trackElementState(field: string, element: StripeElement): void {\n this.elementStates.set(field, { complete: false })\n\n const handleElementChange = (event: { complete: boolean; error?: { message: string } }) => {\n this.elementStates.set(field, { complete: event.complete, error: event.error?.message })\n };\n\n (element as any).on('change', handleElementChange)\n }\n}\n","import type { ProcessPaymentRequest, PaymentResult } from '../types'\nimport type { PaymentExtension } from '../extensions'\n\nexport class PaymentExtensionsManager {\n private extensions: PaymentExtension[] = []\n\n add(extension: PaymentExtension): void {\n this.extensions.push(extension)\n }\n\n async runBeforePayment(request: ProcessPaymentRequest): Promise<ProcessPaymentRequest> {\n let modifiedRequest = request\n for (const ext of this.extensions) {\n if (ext.beforePayment) {\n modifiedRequest = await ext.beforePayment(modifiedRequest)\n }\n }\n return modifiedRequest\n }\n\n async runAfterPayment(result: PaymentResult): Promise<void> {\n await Promise.all(\n this.extensions\n .filter((ext) => ext.afterPayment)\n .map((ext) => ext.afterPayment!(result)),\n )\n }\n\n async runOnError(error: Error): Promise<void> {\n await Promise.all(\n this.extensions\n .filter((ext) => ext.onPaymentError)\n .map((ext) => ext.onPaymentError!(error)),\n )\n }\n}\n","import { StripeAdapter } from '../client/stripe-adapter'\nimport { ElementsManager } from '../client/elements-manager'\nimport { ErrorCode, VerapayError } from '../errors'\nimport { VerapayService } from './verapay-service'\nimport type { ProcessPaymentRequest, PaymentResult } from '../types'\nimport { StripeElements } from '@stripe/stripe-js';\n\nexport interface ProcessPaymentContext {\n merchantId: string\n paymentIntentId: string\n clientSecret: string\n isUsingStripePaymentElement: boolean\n isUsingIndividualFormElements: boolean\n}\n\nexport class PaymentService {\n constructor(\n private stripeAdapter: StripeAdapter,\n private elementsManager: ElementsManager,\n private verapayService: VerapayService,\n ) {}\n\n async process(request: ProcessPaymentRequest, context: ProcessPaymentContext): Promise<PaymentResult> {\n const elements = this.elementsManager.getElements()\n\n await this.validatePaymentCanProceed(elements, context);\n\n await elements!.submit()\n\n const paymentMethodId = await this.stripeAdapter.createPaymentMethod(\n elements!,\n context.isUsingIndividualFormElements,\n )\n\n await this.verapayService.processPrePayment({\n merchantId: context.merchantId,\n paymentIntentId: context.paymentIntentId,\n paymentMethodId,\n customerData: {\n email: request.customerEmail,\n firstName: request.customerFirstName,\n lastName: request.customerLastName,\n },\n description: request.description,\n metadata: request.metadata,\n })\n\n return this.confirmPayment(paymentMethodId, context)\n }\n\n private async validatePaymentCanProceed(elements: StripeElements | null, context: ProcessPaymentContext) {\n if (!elements) {\n throw new VerapayError('Payment form not mounted', ErrorCode.CONFIGURATION_ERROR)\n }\n\n if (context.isUsingStripePaymentElement && context.isUsingIndividualFormElements) {\n throw new VerapayError('Both forms of payment form in use');\n }\n\n if (context.isUsingIndividualFormElements) {\n const validation = await this.elementsManager.validate()\n if (!validation.isValid) {\n throw new VerapayError(validation.errors[0].message, ErrorCode.VALIDATION_ERROR)\n }\n }\n }\n\n private async confirmPayment(\n paymentMethodId: string,\n context: ProcessPaymentContext,\n ): Promise<PaymentResult> {\n const { clientSecret, isUsingStripePaymentElement, isUsingIndividualFormElements } = context\n\n let result\n\n if (isUsingStripePaymentElement) {\n result = await this.stripeAdapter.confirmPayment(paymentMethodId, clientSecret)\n } else if (isUsingIndividualFormElements) {\n result = await this.stripeAdapter.confirmCardPayment(paymentMethodId, clientSecret)\n }\n\n return this.formatPaymentResult(result)\n }\n\n private formatPaymentResult(result: any): PaymentResult {\n return {\n success: result.paymentIntent.status === 'succeeded',\n paymentIntentId: result.paymentIntent.id,\n status: result.paymentIntent.status,\n }\n }\n}\n","import { ErrorCode, VerapayError } from '../errors';\nimport { PaymentData } from '../types';\n\nexport interface InitialisePaymentRequest {\n merchantId: string;\n paymentData: PaymentData;\n}\n\nexport interface InitialisePaymentResponse {\n paymentIntentId: string;\n clientSecret: string;\n connectAccountId: string;\n}\n\nexport interface ProcessPrePaymentRequest {\n merchantId: string;\n paymentIntentId: string;\n paymentMethodId: string;\n customerData: Record<string, any>;\n description?: string;\n metadata?: Record<string, string>;\n}\n\nexport class VerapayService {\n private readonly baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async initialisePayment(\n request: InitialisePaymentRequest\n ): Promise<InitialisePaymentResponse> {\n const { merchantId, paymentData } = request;\n\n try {\n const response = await fetch(`${this.baseUrl}/api/initialise-payment`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': 'example.api.key',\n },\n body: JSON.stringify({\n merchantId,\n paymentData: { ...paymentData, paymentMethodType: 'card' },\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n throw new VerapayError(\n errorData.error || `HTTP error! status: ${response.status}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const data = await response.json();\n\n if (!data.clientSecret || !data.paymentIntentId) {\n throw new VerapayError(\n 'Missing clientSecret or paymentIntentId in server response',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n return {\n paymentIntentId: data.paymentIntentId,\n clientSecret: data.clientSecret,\n connectAccountId: data.connectAccountId,\n };\n } catch (error) {\n if (error instanceof VerapayError) {\n throw error;\n }\n throw new VerapayError(\n error instanceof Error ? error.message : 'Unknown error occurred',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n async processPrePayment(request: ProcessPrePaymentRequest): Promise<void> {\n try {\n const response = await fetch(`${this.baseUrl}/api/process-prepayment`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-forwarded-for': 'example.ip.addr',\n },\n body: JSON.stringify({\n merchantId: request.merchantId,\n paymentIntentId: request.paymentIntentId,\n paymentMethodId: request.paymentMethodId,\n customerData: request.customerData,\n description: request.description,\n metadata: request.metadata,\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n throw new VerapayError(\n errorData.error || `HTTP error! status: ${response.status}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n } catch (error) {\n if (error instanceof VerapayError) {\n throw error;\n }\n throw new VerapayError(\n error instanceof Error ? error.message : 'Unknown error occurred',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n}\n","import { loadStripe } from '@stripe/stripe-js';\nimport { Money } from 'ts-money';\nimport { StripeAdapter } from './stripe-adapter';\nimport { ElementsManager } from './elements-manager';\nimport type { PaymentExtension } from '../extensions';\nimport { PaymentExtensionsManager } from './payment-extensions-manager';\nimport { PaymentService } from '../services/payment-service';\nimport {\n ErrorCode,\n VerapayError,\n PaymentError,\n ValidationError,\n} from '../errors';\nimport { VerapayService } from '../services/verapay-service';\nimport type {\n VerapayConfig,\n ProcessPaymentRequest,\n PaymentResult,\n} from '../types';\n\nexport class VerapayClient {\n private static readonly STRIPE_PUBLISHABLE_KEY =\n 'pk_live_51T04b5GzlW4meYBLBylH3vfoILSU2bGysbeqiG4bLajimWO4WRv1pROt7ZUhTwVqBXvwOCHBYFUtwnZ5ZgV9vBDT00IlUeRxax';\n private static readonly STRIPE_PUBLISHABLE_KEY_TEST_MODE =\n 'pk_test_51TKE9hGhFtMLMQ7kOYMRzsV7kaQhyRNFO7KDNkSvtPSZClV67x9EJkmkEiWTUsjLpkBdRIx55568T5m28g50Mraj00nhMFqAIG';\n\n private static readonly BACKEND_URL = 'https://api.verapay.app';\n private static readonly BACKEND_URL_TEST_MODE = 'https://test-api.verapay.app';\n\n private config: VerapayConfig;\n private verapayService: VerapayService;\n private extensionsManager: PaymentExtensionsManager;\n\n private stripeAdapter: StripeAdapter | null = null;\n private elementsManager: ElementsManager | null = null;\n private paymentService: PaymentService | null = null;\n\n private isUsingStripePaymentElement: boolean = false;\n private isUsingIndividualFormElements: boolean = false;\n\n private clientSecret: string | null = null;\n private paymentIntentId: string | null = null;\n\n constructor(config: VerapayConfig) {\n this.config = config;\n\n const backendUrl = config.enableTestMode\n ? VerapayClient.BACKEND_URL_TEST_MODE\n : VerapayClient.BACKEND_URL;\n\n this.verapayService = new VerapayService(backendUrl);\n this.extensionsManager = new PaymentExtensionsManager();\n }\n\n async initialize(): Promise<void> {\n this.validatePaymentInitialisation()\n\n const { clientSecret, paymentIntentId } =\n await this.verapayService.initialisePayment({\n merchantId: this.config.merchantId,\n paymentData: this.config.paymentData\n });\n\n this.clientSecret = clientSecret;\n this.paymentIntentId = paymentIntentId;\n\n const stripeKey = this.config.enableTestMode\n ? VerapayClient.STRIPE_PUBLISHABLE_KEY_TEST_MODE\n : VerapayClient.STRIPE_PUBLISHABLE_KEY;\n\n const stripe = await loadStripe(stripeKey);\n\n if (!stripe) {\n throw new VerapayError(\n 'Failed to load Stripe',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n this.stripeAdapter = new StripeAdapter(stripe);\n this.elementsManager = new ElementsManager(\n stripe,\n this.config,\n clientSecret\n );\n this.paymentService = new PaymentService(\n this.stripeAdapter,\n this.elementsManager,\n this.verapayService\n );\n }\n\n async processPayment(request: ProcessPaymentRequest): Promise<PaymentResult> {\n await this.ensureInitialized();\n\n let modifiedRequest =\n await this.extensionsManager.runBeforePayment(request);\n\n try {\n const paymentResult = await this.paymentService!.process(\n modifiedRequest,\n {\n merchantId: this.config.merchantId,\n paymentIntentId: this.paymentIntentId!,\n clientSecret: this.clientSecret!,\n isUsingStripePaymentElement: this.isUsingStripePaymentElement,\n isUsingIndividualFormElements: this.isUsingIndividualFormElements,\n }\n );\n\n await this.extensionsManager.runAfterPayment(paymentResult);\n\n return paymentResult;\n } catch (error) {\n await this.extensionsManager.runOnError(error as Error);\n throw this.handlePaymentError(error);\n }\n }\n\n async mountPaymentForm(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountPaymentElement(selector);\n this.isUsingStripePaymentElement = true;\n }\n\n async mountCardNumber(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardNumberElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountCardExpiry(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardExpiryElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountCardCvc(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardCvcElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountAddress(\n selector: string,\n mode: 'billing' | 'shipping'\n ): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountAddressElement(selector, mode);\n this.isUsingIndividualFormElements = true;\n }\n\n addExtension(extension: PaymentExtension): void {\n this.extensionsManager.add(extension);\n }\n\n private async ensureInitialized(): Promise<void> {\n if (!this.stripeAdapter) {\n await this.initialize();\n }\n }\n\n private validatePaymentInitialisation(): void {\n const { amount, currency, partnerFee } = this.config.paymentData;\n\n if (!currency) {\n throw new ValidationError('Currency is required', 'currency');\n }\n\n const uppercaseCurrency = currency.toUpperCase();\n\n const paymentAmount = this.toMoney(amount, uppercaseCurrency, 'amount');\n\n if (paymentAmount.isZero() || paymentAmount.isNegative()) {\n throw new ValidationError('Amount must be greater than 0', 'amount');\n }\n\n if (partnerFee !== undefined) {\n const partnerFeeAmount = this.toMoney(partnerFee, uppercaseCurrency, 'partnerFee');\n\n if (partnerFeeAmount.isNegative()) {\n throw new ValidationError('partnerFee cannot be negative', 'partnerFee');\n }\n\n if (partnerFeeAmount.greaterThan(paymentAmount)) {\n throw new ValidationError('partnerFee cannot exceed the payment amount', 'partnerFee');\n }\n }\n }\n\n private toMoney(value: number, currency: string, fieldName: string): Money {\n try {\n return Money.fromInteger(value, currency);\n } catch {\n throw new ValidationError(\n `${fieldName} must be an integer in the smallest currency unit (e.g., cents for USD)`,\n fieldName\n );\n }\n }\n\n private handlePaymentError(error: any): Error {\n if (error instanceof VerapayError) {\n return error;\n }\n return new PaymentError(error.message || 'Payment failed', error.code);\n }\n}\n","import type { CardValidation } from '../types';\n\nexport class CardValidator {\n validateCardNumber(cardNumber: string): boolean {\n const cleaned = cardNumber.replace(/\\D/g, '');\n\n if (cleaned.length < 13 || cleaned.length > 19) {\n return false;\n }\n\n let sum = 0;\n let isEven = false;\n\n for (let i = cleaned.length - 1; i >= 0; i--) {\n let digit = parseInt(cleaned[i], 10);\n\n if (isEven) {\n digit *= 2;\n if (digit > 9) {\n digit -= 9;\n }\n }\n\n sum += digit;\n isEven = !isEven;\n }\n\n return sum % 10 === 0;\n }\n\n detectCardType(cardNumber: string): string {\n const cleaned = cardNumber.replace(/\\D/g, '');\n\n if (/^4/.test(cleaned)) return 'visa';\n if (/^5[1-5]/.test(cleaned)) return 'mastercard';\n if (/^3[47]/.test(cleaned)) return 'amex';\n if (/^6(?:011|5)/.test(cleaned)) return 'discover';\n\n return 'unknown';\n }\n\n validateExpiry(month: number, year: number): boolean {\n const now = new Date();\n const currentYear = now.getFullYear();\n const currentMonth = now.getMonth() + 1;\n\n if (month < 1 || month > 12) {\n return false;\n }\n\n const fullYear = year < 100 ? 2000 + year : year;\n\n if (fullYear < currentYear) {\n return false;\n }\n\n if (fullYear === currentYear && month < currentMonth) {\n return false;\n }\n\n return true;\n }\n\n validateCVC(cvc: string, cardType: string = 'unknown'): boolean {\n const cleaned = cvc.replace(/\\D/g, '');\n\n if (cardType === 'amex') {\n return cleaned.length === 4;\n }\n\n return cleaned.length === 3 || cleaned.length === 4;\n }\n\n validateAll(\n cardNumber: string,\n expiryMonth: number,\n expiryYear: number,\n cvc: string\n ): CardValidation {\n const cardType = this.detectCardType(cardNumber);\n\n return {\n number: {\n isValid: this.validateCardNumber(cardNumber),\n cardType: cardType as any,\n },\n expiry: {\n isValid: this.validateExpiry(expiryMonth, expiryYear),\n month: expiryMonth,\n year: expiryYear,\n },\n cvc: {\n isValid: this.validateCVC(cvc, cardType),\n length: cvc.replace(/\\D/g, '').length,\n },\n };\n }\n}\n","export class InputSanitizer {\n static sanitizeCardNumber(input: string): string {\n return input.replace(/\\D/g, '');\n }\n\n static formatCardNumber(input: string): string {\n const cleaned = this.sanitizeCardNumber(input);\n return cleaned.replace(/(\\d{4})/g, '$1 ').trim();\n }\n\n static sanitizeCVC(input: string): string {\n return input.replace(/\\D/g, '').slice(0, 4);\n }\n\n static sanitizeExpiry(input: string): { month: number; year: number } | null {\n const cleaned = input.replace(/\\D/g, '');\n\n if (cleaned.length === 4) {\n return {\n month: parseInt(cleaned.slice(0, 2), 10),\n year: parseInt(cleaned.slice(2, 4), 10),\n };\n } else if (cleaned.length === 6) {\n return {\n month: parseInt(cleaned.slice(0, 2), 10),\n year: parseInt(cleaned.slice(2, 6), 10),\n };\n }\n\n return null;\n }\n}\n","export { VerapayClient } from './client/verapay-client';\nexport { VerapayService } from './services/verapay-service';\n\nexport type {\n InitialisePaymentRequest,\n InitialisePaymentResponse,\n ProcessPrePaymentRequest,\n} from './services/verapay-service';\n\nexport type {\n VerapayConfig,\n ElementsConfig,\n ProcessPaymentRequest,\n PaymentResult,\n CardValidation,\n ErrorDetails,\n ErrorCode,\n} from './types';\n\nexport {\n VerapayError,\n ValidationError,\n PaymentError,\n ErrorFormatter,\n} from './errors';\n\nexport { CardValidator, InputSanitizer } from './validation';\n\nexport type {\n PaymentExtension,\n DatabaseExtension,\n AnalyticsExtension,\n} from './extensions';\n\nexport const VERSION = '0.0.1';\n"]}
1
+ {"version":3,"sources":["../src/errors/verapay-error.ts","../src/errors/validation-error.ts","../src/errors/payment-error.ts","../src/errors/error-formatter.ts","../src/client/stripe-adapter.ts","../src/client/elements-manager.ts","../src/client/payment-extensions-manager.ts","../src/services/payment-service.ts","../src/services/verapay-service.ts","../src/client/verapay-client.ts","../src/validation/card-validator.ts","../src/validation/input-sanitizer.ts","../src/index.ts"],"names":["VerapayError","_VerapayError","message","code","details","ValidationError","field","metadata","PaymentError","_PaymentError","stripeCode","ErrorFormatter","error","StripeAdapter","stripe","paymentMethodId","clientSecret","result","elements","isUsingIndividualFormElements","address","DEFAULT_CARD_ELEMENT_CONFIG","FIELD_LABELS","ElementsManager","config","selector","elementsConfig","element","mode","fieldType","options","formFieldType","errors","state","handleElementChange","event","PaymentExtensionsManager","extension","request","modifiedRequest","ext","PaymentService","stripeAdapter","elementsManager","verapayService","context","validation","isUsingStripePaymentElement","VerapayService","baseUrl","apiKey","merchantId","paymentData","response","errorData","data","status","record","candidates","candidate","_VerapayClient","backendUrl","paymentIntentId","stripePublishableKey","loadStripe","paymentResult","amount","currency","partnerFee","uppercaseCurrency","paymentAmount","partnerFeeAmount","value","fieldName","Money","VerapayClient","CardValidator","cardNumber","cleaned","sum","isEven","i","digit","month","year","now","currentYear","currentMonth","fullYear","cvc","cardType","expiryMonth","expiryYear","InputSanitizer","input","VERSION"],"mappings":"mFAGO,IAAMA,CAAAA,CAAN,MAAMC,CAAAA,SAAqB,KAAM,CAItC,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,cAAA,CAAeA,CAAAA,CAAuD,CAC3E,IAAMhB,EAAUgB,CAAAA,CAAM,OAAA,CAAQ,KAAA,CAAO,EAAE,CAAA,CAEvC,OAAIhB,CAAAA,CAAQ,MAAA,GAAW,EACd,CACL,KAAA,CAAO,QAAA,CAASA,CAAAA,CAAQ,MAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,EACvC,IAAA,CAAM,QAAA,CAASA,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,CACxC,CAAA,CACSA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CACrB,CACL,KAAA,CAAO,QAAA,CAASA,CAAAA,CAAQ,MAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,CAAA,CACvC,IAAA,CAAM,QAAA,CAASA,CAAAA,CAAQ,MAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,CACxC,CAAA,CAGK,IACT,CACF,MCGaiB,EAAAA,CAAU","file":"index.cjs","sourcesContent":["import type { ErrorDetails } from '../types';\nimport { ErrorCode } from '../types';\n\nexport class VerapayError extends Error {\n public readonly code: ErrorCode;\n public readonly details: ErrorDetails;\n\n constructor(\n message: string,\n code: ErrorCode = ErrorCode.PAYMENT_FAILED,\n details?: Partial<ErrorDetails>\n ) {\n super(message);\n this.name = 'VerapayError';\n this.code = code;\n this.details = {\n code,\n message,\n formattedMessage: this.formatMessage(message, code),\n ...details,\n };\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, VerapayError);\n }\n }\n\n private formatMessage(message: string, code: ErrorCode): string {\n const messageMap: Record<ErrorCode, string> = {\n [ErrorCode.VALIDATION_ERROR]:\n 'Please check your payment information and try again.',\n [ErrorCode.PAYMENT_FAILED]:\n 'Your payment could not be processed. Please try again.',\n [ErrorCode.AUTHENTICATION_FAILED]:\n 'Payment authentication failed. Please try again.',\n [ErrorCode.NETWORK_ERROR]:\n 'Network error. Please check your connection and try again.',\n [ErrorCode.STRIPE_ERROR]:\n 'Payment service error. Please try again later.',\n [ErrorCode.CONFIGURATION_ERROR]:\n 'Configuration error. Please contact support.',\n [ErrorCode.CARD_DECLINED]:\n 'Your card was declined. Please use a different payment method.',\n [ErrorCode.INSUFFICIENT_FUNDS]:\n 'Insufficient funds. Please use a different payment method.',\n [ErrorCode.EXPIRED_CARD]:\n 'Your card has expired. Please use a different payment method.',\n };\n\n return messageMap[code] || message;\n }\n\n toJSON() {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n details: this.details,\n };\n }\n}\n","import { VerapayError } from './verapay-error';\nimport { ErrorCode } from '../types';\n\nexport class ValidationError extends VerapayError {\n constructor(message: string, field?: string, metadata?: Record<string, any>) {\n super(message, ErrorCode.VALIDATION_ERROR, {\n field,\n metadata,\n });\n this.name = 'ValidationError';\n }\n}\n","import { VerapayError } from './verapay-error';\nimport { ErrorCode } from '../types';\n\nexport class PaymentError extends VerapayError {\n constructor(\n message: string,\n stripeCode?: string,\n metadata?: Record<string, any>\n ) {\n const code = PaymentError.mapStripeCode(stripeCode);\n super(message, code, {\n stripeCode,\n metadata,\n });\n this.name = 'PaymentError';\n }\n\n private static mapStripeCode(stripeCode?: string): ErrorCode {\n if (!stripeCode) return ErrorCode.PAYMENT_FAILED;\n\n const codeMap: Record<string, ErrorCode> = {\n card_declined: ErrorCode.CARD_DECLINED,\n insufficient_funds: ErrorCode.INSUFFICIENT_FUNDS,\n expired_card: ErrorCode.EXPIRED_CARD,\n incorrect_cvc: ErrorCode.VALIDATION_ERROR,\n processing_error: ErrorCode.PAYMENT_FAILED,\n authentication_failed: ErrorCode.AUTHENTICATION_FAILED,\n };\n\n return codeMap[stripeCode] || ErrorCode.PAYMENT_FAILED;\n }\n}\n","import type { ErrorDetails } from '../types';\n\nexport class ErrorFormatter {\n static formatForUser(error: Error | ErrorDetails): string {\n if ('formattedMessage' in error) {\n return error.formattedMessage;\n }\n if (\n 'details' in error &&\n error.details &&\n typeof error.details === 'object' &&\n 'formattedMessage' in error.details &&\n typeof error.details.formattedMessage === 'string'\n ) {\n return error.details.formattedMessage;\n }\n return 'An unexpected error occurred. Please try again.';\n }\n\n static formatForDeveloper(error: Error | ErrorDetails): string {\n if ('code' in error && 'message' in error) {\n return `[${error.code}] ${error.message}`;\n }\n return error.message || 'Unknown error';\n }\n\n static toJSON(error: Error | ErrorDetails): Record<string, any> {\n if ('toJSON' in error && typeof error.toJSON === 'function') {\n return error.toJSON();\n }\n\n return {\n name: (error as Error).name || 'Error',\n message: error.message,\n ...('code' in error && { code: error.code }),\n ...('details' in error && { details: error.details }),\n };\n }\n}\n","import type { PaymentIntent, Stripe, StripeElements } from '@stripe/stripe-js';\nimport { PaymentError } from '../errors';\n\nexport class StripeAdapter {\n constructor(private stripe: Stripe) {}\n\n async confirmPayment(\n paymentMethodId: string,\n clientSecret: string\n ): Promise<{ paymentIntent: PaymentIntent }> {\n const result = await this.stripe.confirmPayment({\n clientSecret,\n confirmParams: {\n payment_method: paymentMethodId,\n return_url: window.location.href,\n },\n redirect: 'if_required',\n });\n\n if (result.error) {\n throw new PaymentError(\n result.error.message || 'Payment failed',\n result.error.code\n );\n }\n\n return result as { paymentIntent: PaymentIntent };\n }\n\n async confirmCardPayment(\n paymentMethodId: string,\n clientSecret: string\n ): Promise<{ paymentIntent: PaymentIntent }> {\n const result = await this.stripe.confirmCardPayment(clientSecret, {\n payment_method: paymentMethodId,\n });\n\n if (result.error) {\n throw new PaymentError(\n result.error.message || 'Payment failed',\n result.error.code\n );\n }\n\n return result as { paymentIntent: PaymentIntent };\n }\n\n async createPaymentMethod(\n elements: StripeElements,\n isUsingIndividualFormElements: boolean = false\n ): Promise<string> {\n let result;\n\n if (!isUsingIndividualFormElements) {\n result = await this.stripe.createPaymentMethod({\n elements,\n });\n } else {\n // @ts-ignore - Stripe types don't include mode parameter for getElement\n const addressElement = await elements.getElement('address', { mode: 'billing' })!.getValue();\n const address = addressElement!.value;\n\n result = await this.stripe.createPaymentMethod({\n type: 'card',\n card: elements.getElement('cardNumber')!,\n billing_details: {\n name: address.name,\n address: {\n ...address.address,\n line2: address.address.line2 ?? undefined,\n },\n },\n });\n }\n\n if (result.error || !result.paymentMethod) {\n throw new PaymentError(\n result.error?.message || 'Failed to create payment method',\n result.error?.code\n );\n }\n\n return result.paymentMethod.id;\n }\n}\n","import type {\n Stripe,\n StripeElements,\n StripeElement,\n StripePaymentElement,\n StripeCardNumberElement,\n PaymentWalletsOption,\n} from '@stripe/stripe-js';\nimport type { VerapayConfig, ValidationError, ValidationResult } from '../types';\nimport { VerapayError, ErrorCode } from '../errors';\n\ntype ElementState = { complete: boolean; error?: string }\n\nconst DEFAULT_CARD_ELEMENT_CONFIG = {\n showIcon: true,\n iconStyle: 'solid' as const,\n placeholders: {\n cardNumber: '1234 1234 1234 1234',\n cardExpiry: 'MM / YY - TESTING',\n cardCvc: 'CVC',\n },\n style: {\n base: {\n color: '#333333',\n fontFamily: 'system-ui, -apple-system, sans-serif',\n fontSize: '16px',\n '::placeholder': { color: '#aab7c4' },\n },\n complete: {\n color: '#333333',\n },\n empty: {},\n invalid: {\n color: '#df1b41',\n },\n },\n}\n\nconst FIELD_LABELS: Record<string, string> = {\n cardNumber: 'Card number',\n cardExpiry: 'Expiry date',\n cardCvc: 'CVC',\n address: 'Address',\n}\n\nexport class ElementsManager {\n private elements: StripeElements | null = null;\n private mountedElements: Map<string, StripeElement> = new Map();\n private elementStates: Map<string, ElementState> = new Map();\n\n constructor(\n private stripe: Stripe,\n private config: VerapayConfig,\n private clientSecret: string\n ) {\n if (!clientSecret) {\n throw new VerapayError(\n 'Client secret not initialized',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n mountPaymentElement(selector: string): void {\n if (!this.elements) {\n const elementsConfig = {\n clientSecret: this.clientSecret,\n appearance: this.config.appearance,\n locale: this.config.locale,\n fonts: this.config.fonts,\n paymentMethodCreation: 'manual',\n };\n\n this.elements = this.stripe.elements(elementsConfig);\n }\n\n const container = document.querySelector(selector);\n\n if (!container) {\n throw new VerapayError(\n `Element not found: ${selector}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const element = this.elements.create('payment', {\n layout: 'tabs',\n wallets: { link: 'never' } as unknown as PaymentWalletsOption,\n }) as StripePaymentElement;\n\n element.mount(selector);\n this.mountedElements.set('payment', element);\n }\n\n mountCardNumberElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardNumber', this.cardElementOptions('cardNumber'));\n }\n\n mountCardExpiryElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardExpiry', this.cardElementOptions('cardExpiry'));\n }\n\n mountCardCvcElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardCvc', this.cardElementOptions('cardCvc'));\n }\n\n mountAddressElement(selector: string, mode: 'billing' | 'shipping'): void {\n this.mountIndividualFormElement(selector, 'address', { mode });\n }\n\n private cardElementOptions(fieldType: 'cardNumber' | 'cardExpiry' | 'cardCvc'): Record<string, unknown> {\n const { elementsConfig } = this.config;\n const options: Record<string, unknown> = {\n placeholder: elementsConfig?.placeholders?.[fieldType] ?? DEFAULT_CARD_ELEMENT_CONFIG.placeholders[fieldType],\n style: {\n base: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.base, ...elementsConfig?.style?.base },\n complete: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.complete, ...elementsConfig?.style?.complete },\n empty: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.empty, ...elementsConfig?.style?.empty },\n invalid: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.invalid, ...elementsConfig?.style?.invalid },\n },\n };\n\n if (fieldType === 'cardNumber') {\n options.showIcon = elementsConfig?.showIcon ?? DEFAULT_CARD_ELEMENT_CONFIG.showIcon;\n options.iconStyle = elementsConfig?.iconStyle ?? DEFAULT_CARD_ELEMENT_CONFIG.iconStyle;\n }\n\n return options;\n }\n\n private mountIndividualFormElement(selector: string, formFieldType: 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address', options?: Record<string, unknown>) {\n const container = document.querySelector(selector);\n\n if (!container) {\n throw new VerapayError(\n `Element not found: ${selector}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const element = this.createIndividualFormElement(formFieldType, options) as StripeCardNumberElement;\n element.mount(selector);\n\n this.mountedElements.set(formFieldType, element);\n this.trackElementState(formFieldType, element);\n }\n\n private createIndividualFormElement(\n formFieldType: any,\n options?: Record<string, unknown>\n ): StripeElement {\n if (!this.elements) {\n // For individual card elements, don't pass clientSecret\n // It's only needed when creating Payment Element or confirming payment\n this.elements = this.stripe.elements({\n appearance: this.config.appearance,\n locale: this.config.locale,\n fonts: this.config.fonts,\n paymentMethodCreation: 'manual',\n });\n }\n\n return this.elements.create(formFieldType, options);\n }\n\n async validate(): Promise<ValidationResult> {\n const errors: ValidationError[] = []\n\n for (const [field, state] of this.elementStates.entries()) {\n if (!state.complete) {\n errors.push({\n field,\n message: state.error ?? `${FIELD_LABELS[field] ?? field} failed validation`,\n })\n }\n }\n\n return { isValid: errors.length === 0, errors }\n }\n\n getElements(): StripeElements | null {\n return this.elements;\n }\n\n unmountAll(): void {\n for (const element of this.mountedElements.values()) {\n element.unmount();\n }\n this.mountedElements.clear();\n this.elementStates.clear();\n }\n\n private trackElementState(field: string, element: StripeElement): void {\n this.elementStates.set(field, { complete: false })\n\n const handleElementChange = (event: { complete: boolean; error?: { message: string } }) => {\n this.elementStates.set(field, { complete: event.complete, error: event.error?.message })\n };\n\n (element as any).on('change', handleElementChange)\n }\n}\n","import type { ProcessPaymentRequest, PaymentResult } from '../types'\nimport type { PaymentExtension } from '../extensions'\n\nexport class PaymentExtensionsManager {\n private extensions: PaymentExtension[] = []\n\n add(extension: PaymentExtension): void {\n this.extensions.push(extension)\n }\n\n async runBeforePayment(request: ProcessPaymentRequest): Promise<ProcessPaymentRequest> {\n let modifiedRequest = request\n for (const ext of this.extensions) {\n if (ext.beforePayment) {\n modifiedRequest = await ext.beforePayment(modifiedRequest)\n }\n }\n return modifiedRequest\n }\n\n async runAfterPayment(result: PaymentResult): Promise<void> {\n await Promise.all(\n this.extensions\n .filter((ext) => ext.afterPayment)\n .map((ext) => ext.afterPayment!(result)),\n )\n }\n\n async runOnError(error: Error): Promise<void> {\n await Promise.all(\n this.extensions\n .filter((ext) => ext.onPaymentError)\n .map((ext) => ext.onPaymentError!(error)),\n )\n }\n}\n","import { StripeAdapter } from '../client/stripe-adapter'\nimport { ElementsManager } from '../client/elements-manager'\nimport { ErrorCode, VerapayError } from '../errors'\nimport { VerapayService } from './verapay-service'\nimport type { ProcessPaymentRequest, PaymentResult } from '../types'\nimport { StripeElements } from '@stripe/stripe-js';\n\nexport interface ProcessPaymentContext {\n merchantId: string\n paymentIntentId: string\n clientSecret: string\n amount: number\n currency: string\n isUsingStripePaymentElement: boolean\n isUsingIndividualFormElements: boolean\n}\n\nexport class PaymentService {\n constructor(\n private stripeAdapter: StripeAdapter,\n private elementsManager: ElementsManager,\n private verapayService: VerapayService,\n ) {}\n\n async process(request: ProcessPaymentRequest, context: ProcessPaymentContext): Promise<PaymentResult> {\n const elements = this.elementsManager.getElements()\n\n await this.validatePaymentCanProceed(elements, context);\n\n await elements!.submit()\n\n const paymentMethodId = await this.stripeAdapter.createPaymentMethod(\n elements!,\n context.isUsingIndividualFormElements,\n )\n\n await this.verapayService.processPrePayment({\n merchantId: context.merchantId,\n paymentIntentId: context.paymentIntentId,\n paymentMethodId,\n amount: context.amount,\n currency: context.currency,\n customerData: {\n email: request.customerEmail,\n firstName: request.customerFirstName,\n lastName: request.customerLastName,\n },\n description: request.description,\n metadata: request.metadata,\n })\n\n return this.confirmPayment(paymentMethodId, context)\n }\n\n private async validatePaymentCanProceed(elements: StripeElements | null, context: ProcessPaymentContext) {\n if (!elements) {\n throw new VerapayError('Payment form not mounted', ErrorCode.CONFIGURATION_ERROR)\n }\n\n if (context.isUsingStripePaymentElement && context.isUsingIndividualFormElements) {\n throw new VerapayError('Both forms of payment form in use');\n }\n\n if (context.isUsingIndividualFormElements) {\n const validation = await this.elementsManager.validate()\n if (!validation.isValid) {\n throw new VerapayError(validation.errors[0].message, ErrorCode.VALIDATION_ERROR)\n }\n }\n }\n\n private async confirmPayment(\n paymentMethodId: string,\n context: ProcessPaymentContext,\n ): Promise<PaymentResult> {\n const { clientSecret, isUsingStripePaymentElement, isUsingIndividualFormElements } = context\n\n let result\n\n if (isUsingStripePaymentElement) {\n result = await this.stripeAdapter.confirmPayment(paymentMethodId, clientSecret)\n } else if (isUsingIndividualFormElements) {\n result = await this.stripeAdapter.confirmCardPayment(paymentMethodId, clientSecret)\n }\n\n return this.formatPaymentResult(result)\n }\n\n private formatPaymentResult(result: any): PaymentResult {\n return {\n success: result.paymentIntent.status === 'succeeded',\n paymentIntentId: result.paymentIntent.id,\n status: result.paymentIntent.status,\n }\n }\n}\n","import { ErrorCode, VerapayError } from '../errors';\nimport { PaymentData } from '../types';\n\nexport interface InitialisePaymentRequest {\n merchantId: string;\n paymentData: PaymentData;\n}\n\nexport interface InitialisePaymentResponse {\n paymentIntentId: string;\n clientSecret: string;\n connectAccountId: string;\n stripePublishableKey: string;\n}\n\nexport interface ProcessPrePaymentRequest {\n merchantId: string;\n paymentIntentId: string;\n paymentMethodId: string;\n amount: number;\n currency: string;\n customerData: Record<string, any>;\n description?: string;\n metadata?: Record<string, string>;\n}\n\nexport class VerapayService {\n private readonly baseUrl: string;\n private readonly apiKey: string;\n\n constructor(baseUrl: string, apiKey: string) {\n this.baseUrl = baseUrl;\n this.apiKey = apiKey;\n }\n\n async initialisePayment(\n request: InitialisePaymentRequest\n ): Promise<InitialisePaymentResponse> {\n const { merchantId, paymentData } = request;\n\n try {\n const response = await fetch(`${this.baseUrl}/api/initialise-payment`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': this.apiKey,\n },\n body: JSON.stringify({\n merchantId,\n paymentData: { ...paymentData, paymentMethodType: 'card' },\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n throw new VerapayError(\n this.extractErrorMessage(errorData, response.status),\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const data = await response.json();\n\n if (!data.clientSecret || !data.paymentIntentId) {\n throw new VerapayError(\n 'Missing clientSecret or paymentIntentId in server response',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n return {\n paymentIntentId: data.paymentIntentId,\n clientSecret: data.clientSecret,\n connectAccountId: data.connectAccountId,\n stripePublishableKey: data.stripePublishableKey,\n };\n } catch (error) {\n if (error instanceof VerapayError) {\n throw error;\n }\n throw new VerapayError(\n error instanceof Error ? error.message : 'Unknown error occurred',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n async processPrePayment(request: ProcessPrePaymentRequest): Promise<void> {\n try {\n const response = await fetch(`${this.baseUrl}/api/process-prepayment`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': this.apiKey,\n },\n body: JSON.stringify({\n merchantId: request.merchantId,\n paymentIntentId: request.paymentIntentId,\n paymentMethodId: request.paymentMethodId,\n amount: request.amount,\n currency: request.currency,\n customerData: request.customerData,\n description: request.description,\n metadata: request.metadata,\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n throw new VerapayError(\n this.extractErrorMessage(errorData, response.status),\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n } catch (error) {\n if (error instanceof VerapayError) {\n throw error;\n }\n throw new VerapayError(\n error instanceof Error ? error.message : 'Unknown error occurred',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n private extractErrorMessage(errorData: unknown, status: number): string {\n if (!errorData || typeof errorData !== 'object') {\n return `HTTP error! status: ${status}`;\n }\n\n const record = errorData as Record<string, unknown>;\n const candidates = [record.error, record.message, record.details];\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n\n if (candidate && typeof candidate === 'object') {\n try {\n return JSON.stringify(candidate);\n } catch {\n // Ignore serialization issues and continue trying fallback messages.\n }\n }\n }\n\n return `HTTP error! status: ${status}`;\n }\n}\n","import { loadStripe } from '@stripe/stripe-js';\nimport { Money } from 'ts-money';\nimport { StripeAdapter } from './stripe-adapter';\nimport { ElementsManager } from './elements-manager';\nimport type { PaymentExtension } from '../extensions';\nimport { PaymentExtensionsManager } from './payment-extensions-manager';\nimport { PaymentService } from '../services/payment-service';\nimport {\n ErrorCode,\n VerapayError,\n PaymentError,\n ValidationError,\n} from '../errors';\nimport { VerapayService } from '../services/verapay-service';\nimport type {\n VerapayConfig,\n ProcessPaymentRequest,\n PaymentResult,\n} from '../types';\n\nexport class VerapayClient {\n private static readonly BACKEND_URL = 'https://api.verapay.app';\n private static readonly BACKEND_URL_TEST_MODE = 'https://test-api.verapay.app';\n\n private config: VerapayConfig;\n private verapayService: VerapayService;\n private extensionsManager: PaymentExtensionsManager;\n\n private stripeAdapter: StripeAdapter | null = null;\n private elementsManager: ElementsManager | null = null;\n private paymentService: PaymentService | null = null;\n\n private isUsingStripePaymentElement: boolean = false;\n private isUsingIndividualFormElements: boolean = false;\n\n private clientSecret: string | null = null;\n private paymentIntentId: string | null = null;\n\n constructor(config: VerapayConfig) {\n if (!config.apiKey) {\n throw new VerapayError(\n 'apiKey is required. Pass your Verapay publishable key (vpy_pk_test_... or vpy_pk_live_...) when constructing VerapayClient.',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n this.config = config;\n\n if (!this.config.apiKey.includes(\"_pk_\") && typeof window !== \"undefined\") {\n console.warn(\n \"Verapay Security Warning: You are using a Secret Key in a frontend environment. Please use a Publishable Key (vpy_pk_...) instead.\"\n );\n }\n\n const backendUrl =\n this.config.apiUrlOverride ||\n (this.isTestKey()\n ? VerapayClient.BACKEND_URL_TEST_MODE\n : VerapayClient.BACKEND_URL);\n\n this.verapayService = new VerapayService(backendUrl, this.config.apiKey);\n this.extensionsManager = new PaymentExtensionsManager();\n }\n\n async initialize(): Promise<void> {\n this.validatePaymentInitialisation()\n\n const { clientSecret, paymentIntentId, stripePublishableKey } =\n await this.verapayService.initialisePayment({\n merchantId: this.config.merchantId ?? '',\n paymentData: this.config.paymentData\n });\n\n this.clientSecret = clientSecret;\n this.paymentIntentId = paymentIntentId;\n\n const stripe = await loadStripe(stripePublishableKey);\n\n if (!stripe) {\n throw new VerapayError(\n 'Failed to load Stripe',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n this.stripeAdapter = new StripeAdapter(stripe);\n this.elementsManager = new ElementsManager(\n stripe,\n this.config,\n clientSecret\n );\n this.paymentService = new PaymentService(\n this.stripeAdapter,\n this.elementsManager,\n this.verapayService\n );\n }\n\n async processPayment(request: ProcessPaymentRequest): Promise<PaymentResult> {\n await this.ensureInitialized();\n\n let modifiedRequest =\n await this.extensionsManager.runBeforePayment(request);\n\n try {\n const paymentResult = await this.paymentService!.process(\n modifiedRequest,\n {\n merchantId: this.config.merchantId ?? '',\n paymentIntentId: this.paymentIntentId!,\n clientSecret: this.clientSecret!,\n amount: this.config.paymentData.amount,\n currency: this.config.paymentData.currency,\n isUsingStripePaymentElement: this.isUsingStripePaymentElement,\n isUsingIndividualFormElements: this.isUsingIndividualFormElements,\n }\n );\n\n await this.extensionsManager.runAfterPayment(paymentResult);\n\n return paymentResult;\n } catch (error) {\n await this.extensionsManager.runOnError(error as Error);\n throw this.handlePaymentError(error);\n }\n }\n\n async mountPaymentForm(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountPaymentElement(selector);\n this.isUsingStripePaymentElement = true;\n }\n\n async mountCardNumber(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardNumberElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountCardExpiry(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardExpiryElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountCardCvc(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardCvcElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountAddress(\n selector: string,\n mode: 'billing' | 'shipping'\n ): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountAddressElement(selector, mode);\n this.isUsingIndividualFormElements = true;\n }\n\n addExtension(extension: PaymentExtension): void {\n this.extensionsManager.add(extension);\n }\n\n private async ensureInitialized(): Promise<void> {\n if (!this.stripeAdapter) {\n await this.initialize();\n }\n }\n\n private validatePaymentInitialisation(): void {\n const { amount, currency, partnerFee } = this.config.paymentData;\n\n if (!currency) {\n throw new ValidationError('Currency is required', 'currency');\n }\n\n const uppercaseCurrency = currency.toUpperCase();\n\n const paymentAmount = this.toMoney(amount, uppercaseCurrency, 'amount');\n\n if (paymentAmount.isZero() || paymentAmount.isNegative()) {\n throw new ValidationError('Amount must be greater than 0', 'amount');\n }\n\n if (partnerFee !== undefined) {\n const partnerFeeAmount = this.toMoney(partnerFee, uppercaseCurrency, 'partnerFee');\n\n if (partnerFeeAmount.isNegative()) {\n throw new ValidationError('partnerFee cannot be negative', 'partnerFee');\n }\n\n if (partnerFeeAmount.greaterThan(paymentAmount)) {\n throw new ValidationError('partnerFee cannot exceed the payment amount', 'partnerFee');\n }\n }\n }\n\n private toMoney(value: number, currency: string, fieldName: string): Money {\n try {\n return Money.fromInteger(value, currency);\n } catch {\n throw new ValidationError(\n `${fieldName} must be an integer in the smallest currency unit (e.g., cents for USD)`,\n fieldName\n );\n }\n }\n\n private isTestKey(): boolean {\n return (\n this.config.apiKey.startsWith('vpy_pk_test_') ||\n this.config.apiKey.startsWith('vpy_test_')\n );\n }\n\n private handlePaymentError(error: any): Error {\n if (error instanceof VerapayError) {\n return error;\n }\n return new PaymentError(error.message || 'Payment failed', error.code);\n }\n}\n","import type { CardValidation } from '../types';\n\nexport class CardValidator {\n validateCardNumber(cardNumber: string): boolean {\n const cleaned = cardNumber.replace(/\\D/g, '');\n\n if (cleaned.length < 13 || cleaned.length > 19) {\n return false;\n }\n\n let sum = 0;\n let isEven = false;\n\n for (let i = cleaned.length - 1; i >= 0; i--) {\n let digit = parseInt(cleaned[i], 10);\n\n if (isEven) {\n digit *= 2;\n if (digit > 9) {\n digit -= 9;\n }\n }\n\n sum += digit;\n isEven = !isEven;\n }\n\n return sum % 10 === 0;\n }\n\n detectCardType(cardNumber: string): string {\n const cleaned = cardNumber.replace(/\\D/g, '');\n\n if (/^4/.test(cleaned)) return 'visa';\n if (/^5[1-5]/.test(cleaned)) return 'mastercard';\n if (/^3[47]/.test(cleaned)) return 'amex';\n if (/^6(?:011|5)/.test(cleaned)) return 'discover';\n\n return 'unknown';\n }\n\n validateExpiry(month: number, year: number): boolean {\n const now = new Date();\n const currentYear = now.getFullYear();\n const currentMonth = now.getMonth() + 1;\n\n if (month < 1 || month > 12) {\n return false;\n }\n\n const fullYear = year < 100 ? 2000 + year : year;\n\n if (fullYear < currentYear) {\n return false;\n }\n\n if (fullYear === currentYear && month < currentMonth) {\n return false;\n }\n\n return true;\n }\n\n validateCVC(cvc: string, cardType: string = 'unknown'): boolean {\n const cleaned = cvc.replace(/\\D/g, '');\n\n if (cardType === 'amex') {\n return cleaned.length === 4;\n }\n\n return cleaned.length === 3 || cleaned.length === 4;\n }\n\n validateAll(\n cardNumber: string,\n expiryMonth: number,\n expiryYear: number,\n cvc: string\n ): CardValidation {\n const cardType = this.detectCardType(cardNumber);\n\n return {\n number: {\n isValid: this.validateCardNumber(cardNumber),\n cardType: cardType as any,\n },\n expiry: {\n isValid: this.validateExpiry(expiryMonth, expiryYear),\n month: expiryMonth,\n year: expiryYear,\n },\n cvc: {\n isValid: this.validateCVC(cvc, cardType),\n length: cvc.replace(/\\D/g, '').length,\n },\n };\n }\n}\n","export class InputSanitizer {\n static sanitizeCardNumber(input: string): string {\n return input.replace(/\\D/g, '');\n }\n\n static formatCardNumber(input: string): string {\n const cleaned = this.sanitizeCardNumber(input);\n return cleaned.replace(/(\\d{4})/g, '$1 ').trim();\n }\n\n static sanitizeCVC(input: string): string {\n return input.replace(/\\D/g, '').slice(0, 4);\n }\n\n static sanitizeExpiry(input: string): { month: number; year: number } | null {\n const cleaned = input.replace(/\\D/g, '');\n\n if (cleaned.length === 4) {\n return {\n month: parseInt(cleaned.slice(0, 2), 10),\n year: parseInt(cleaned.slice(2, 4), 10),\n };\n } else if (cleaned.length === 6) {\n return {\n month: parseInt(cleaned.slice(0, 2), 10),\n year: parseInt(cleaned.slice(2, 6), 10),\n };\n }\n\n return null;\n }\n}\n","export { VerapayClient } from './client/verapay-client';\nexport { VerapayService } from './services/verapay-service';\n\nexport type {\n InitialisePaymentRequest,\n InitialisePaymentResponse,\n ProcessPrePaymentRequest,\n} from './services/verapay-service';\n\nexport type {\n VerapayConfig,\n ElementsConfig,\n ProcessPaymentRequest,\n PaymentResult,\n CardValidation,\n ErrorDetails,\n ErrorCode,\n} from './types';\n\nexport {\n VerapayError,\n ValidationError,\n PaymentError,\n ErrorFormatter,\n} from './errors';\n\nexport { CardValidator, InputSanitizer } from './validation';\n\nexport type {\n PaymentExtension,\n DatabaseExtension,\n AnalyticsExtension,\n} from './extensions';\n\nexport const VERSION = '1.1.0';\n"]}
package/dist/index.d.cts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { Appearance, StripeElementLocale, StripeElementsOptions } from '@stripe/stripe-js';
2
2
 
3
3
  interface VerapayConfig {
4
- merchantId: string;
4
+ apiKey: string;
5
+ merchantId?: string;
5
6
  paymentData: PaymentData;
6
7
  appearance?: Appearance;
7
8
  locale?: StripeElementLocale;
8
9
  fonts?: StripeElementsOptions['fonts'];
9
10
  elementsConfig?: ElementsConfig;
10
- enableTestMode?: boolean;
11
+ apiUrlOverride?: string;
11
12
  }
12
13
  interface PaymentData {
13
14
  amount: number;
@@ -97,8 +98,6 @@ interface AnalyticsExtension extends PaymentExtension {
97
98
  }
98
99
 
99
100
  declare class VerapayClient {
100
- private static readonly STRIPE_PUBLISHABLE_KEY;
101
- private static readonly STRIPE_PUBLISHABLE_KEY_TEST_MODE;
102
101
  private static readonly BACKEND_URL;
103
102
  private static readonly BACKEND_URL_TEST_MODE;
104
103
  private config;
@@ -123,6 +122,7 @@ declare class VerapayClient {
123
122
  private ensureInitialized;
124
123
  private validatePaymentInitialisation;
125
124
  private toMoney;
125
+ private isTestKey;
126
126
  private handlePaymentError;
127
127
  }
128
128
 
@@ -134,20 +134,25 @@ interface InitialisePaymentResponse {
134
134
  paymentIntentId: string;
135
135
  clientSecret: string;
136
136
  connectAccountId: string;
137
+ stripePublishableKey: string;
137
138
  }
138
139
  interface ProcessPrePaymentRequest {
139
140
  merchantId: string;
140
141
  paymentIntentId: string;
141
142
  paymentMethodId: string;
143
+ amount: number;
144
+ currency: string;
142
145
  customerData: Record<string, any>;
143
146
  description?: string;
144
147
  metadata?: Record<string, string>;
145
148
  }
146
149
  declare class VerapayService {
147
150
  private readonly baseUrl;
148
- constructor(baseUrl: string);
151
+ private readonly apiKey;
152
+ constructor(baseUrl: string, apiKey: string);
149
153
  initialisePayment(request: InitialisePaymentRequest): Promise<InitialisePaymentResponse>;
150
154
  processPrePayment(request: ProcessPrePaymentRequest): Promise<void>;
155
+ private extractErrorMessage;
151
156
  }
152
157
 
153
158
  declare class VerapayError extends Error {
@@ -196,6 +201,6 @@ declare class InputSanitizer {
196
201
  } | null;
197
202
  }
198
203
 
199
- declare const VERSION = "0.0.1";
204
+ declare const VERSION = "1.1.0";
200
205
 
201
206
  export { type AnalyticsExtension, type CardValidation, CardValidator, type DatabaseExtension, type ElementsConfig, ErrorCode, type ErrorDetails, ErrorFormatter, type InitialisePaymentRequest, type InitialisePaymentResponse, InputSanitizer, PaymentError, type PaymentExtension, type PaymentResult, type ProcessPaymentRequest, type ProcessPrePaymentRequest, VERSION, ValidationError, VerapayClient, type VerapayConfig, VerapayError, VerapayService };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,14 @@
1
1
  import { Appearance, StripeElementLocale, StripeElementsOptions } from '@stripe/stripe-js';
2
2
 
3
3
  interface VerapayConfig {
4
- merchantId: string;
4
+ apiKey: string;
5
+ merchantId?: string;
5
6
  paymentData: PaymentData;
6
7
  appearance?: Appearance;
7
8
  locale?: StripeElementLocale;
8
9
  fonts?: StripeElementsOptions['fonts'];
9
10
  elementsConfig?: ElementsConfig;
10
- enableTestMode?: boolean;
11
+ apiUrlOverride?: string;
11
12
  }
12
13
  interface PaymentData {
13
14
  amount: number;
@@ -97,8 +98,6 @@ interface AnalyticsExtension extends PaymentExtension {
97
98
  }
98
99
 
99
100
  declare class VerapayClient {
100
- private static readonly STRIPE_PUBLISHABLE_KEY;
101
- private static readonly STRIPE_PUBLISHABLE_KEY_TEST_MODE;
102
101
  private static readonly BACKEND_URL;
103
102
  private static readonly BACKEND_URL_TEST_MODE;
104
103
  private config;
@@ -123,6 +122,7 @@ declare class VerapayClient {
123
122
  private ensureInitialized;
124
123
  private validatePaymentInitialisation;
125
124
  private toMoney;
125
+ private isTestKey;
126
126
  private handlePaymentError;
127
127
  }
128
128
 
@@ -134,20 +134,25 @@ interface InitialisePaymentResponse {
134
134
  paymentIntentId: string;
135
135
  clientSecret: string;
136
136
  connectAccountId: string;
137
+ stripePublishableKey: string;
137
138
  }
138
139
  interface ProcessPrePaymentRequest {
139
140
  merchantId: string;
140
141
  paymentIntentId: string;
141
142
  paymentMethodId: string;
143
+ amount: number;
144
+ currency: string;
142
145
  customerData: Record<string, any>;
143
146
  description?: string;
144
147
  metadata?: Record<string, string>;
145
148
  }
146
149
  declare class VerapayService {
147
150
  private readonly baseUrl;
148
- constructor(baseUrl: string);
151
+ private readonly apiKey;
152
+ constructor(baseUrl: string, apiKey: string);
149
153
  initialisePayment(request: InitialisePaymentRequest): Promise<InitialisePaymentResponse>;
150
154
  processPrePayment(request: ProcessPrePaymentRequest): Promise<void>;
155
+ private extractErrorMessage;
151
156
  }
152
157
 
153
158
  declare class VerapayError extends Error {
@@ -196,6 +201,6 @@ declare class InputSanitizer {
196
201
  } | null;
197
202
  }
198
203
 
199
- declare const VERSION = "0.0.1";
204
+ declare const VERSION = "1.1.0";
200
205
 
201
206
  export { type AnalyticsExtension, type CardValidation, CardValidator, type DatabaseExtension, type ElementsConfig, ErrorCode, type ErrorDetails, ErrorFormatter, type InitialisePaymentRequest, type InitialisePaymentResponse, InputSanitizer, PaymentError, type PaymentExtension, type PaymentResult, type ProcessPaymentRequest, type ProcessPrePaymentRequest, VERSION, ValidationError, VerapayClient, type VerapayConfig, VerapayError, VerapayService };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import {loadStripe}from'@stripe/stripe-js';import {Money}from'ts-money';var i=class o extends Error{constructor(e,t="PAYMENT_FAILED",r){super(e),this.name="VerapayError",this.code=t,this.details={code:t,message:e,formattedMessage:this.formatMessage(e,t),...r},Error.captureStackTrace&&Error.captureStackTrace(this,o);}formatMessage(e,t){return {VALIDATION_ERROR:"Please check your payment information and try again.",PAYMENT_FAILED:"Your payment could not be processed. Please try again.",AUTHENTICATION_FAILED:"Payment authentication failed. Please try again.",NETWORK_ERROR:"Network error. Please check your connection and try again.",STRIPE_ERROR:"Payment service error. Please try again later.",CONFIGURATION_ERROR:"Configuration error. Please contact support.",CARD_DECLINED:"Your card was declined. Please use a different payment method.",INSUFFICIENT_FUNDS:"Insufficient funds. Please use a different payment method.",EXPIRED_CARD:"Your card has expired. Please use a different payment method."}[t]||e}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}};var m=class extends i{constructor(e,t,r){super(e,"VALIDATION_ERROR",{field:t,metadata:r}),this.name="ValidationError";}};var l=class o extends i{constructor(e,t,r){let n=o.mapStripeCode(t);super(e,n,{stripeCode:t,metadata:r}),this.name="PaymentError";}static mapStripeCode(e){return e?{card_declined:"CARD_DECLINED",insufficient_funds:"INSUFFICIENT_FUNDS",expired_card:"EXPIRED_CARD",incorrect_cvc:"VALIDATION_ERROR",processing_error:"PAYMENT_FAILED",authentication_failed:"AUTHENTICATION_FAILED"}[e]||"PAYMENT_FAILED":"PAYMENT_FAILED"}};var u=class{static formatForUser(e){return "formattedMessage"in e?e.formattedMessage:"details"in e&&e.details&&typeof e.details=="object"&&"formattedMessage"in e.details&&typeof e.details.formattedMessage=="string"?e.details.formattedMessage:"An unexpected error occurred. Please try again."}static formatForDeveloper(e){return "code"in e&&"message"in e?`[${e.code}] ${e.message}`:e.message||"Unknown error"}static toJSON(e){return "toJSON"in e&&typeof e.toJSON=="function"?e.toJSON():{name:e.name||"Error",message:e.message,..."code"in e&&{code:e.code},..."details"in e&&{details:e.details}}}};var E=class{constructor(e){this.stripe=e;}async confirmPayment(e,t){let r=await this.stripe.confirmPayment({clientSecret:t,confirmParams:{payment_method:e,return_url:window.location.href},redirect:"if_required"});if(r.error)throw new l(r.error.message||"Payment failed",r.error.code);return r}async confirmCardPayment(e,t){let r=await this.stripe.confirmCardPayment(t,{payment_method:e});if(r.error)throw new l(r.error.message||"Payment failed",r.error.code);return r}async createPaymentMethod(e,t=false){let r;if(!t)r=await this.stripe.createPaymentMethod({elements:e});else {let a=(await e.getElement("address",{mode:"billing"}).getValue()).value;r=await this.stripe.createPaymentMethod({type:"card",card:e.getElement("cardNumber"),billing_details:{name:a.name,address:{...a.address,line2:a.address.line2??void 0}}});}if(r.error||!r.paymentMethod)throw new l(r.error?.message||"Failed to create payment method",r.error?.code);return r.paymentMethod.id}};var d={showIcon:true,iconStyle:"solid",placeholders:{cardNumber:"1234 1234 1234 1234",cardExpiry:"MM / YY - TESTING",cardCvc:"CVC"},style:{base:{color:"#333333",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"16px","::placeholder":{color:"#aab7c4"}},complete:{color:"#333333"},empty:{},invalid:{color:"#df1b41"}}},v={cardNumber:"Card number",cardExpiry:"Expiry date",cardCvc:"CVC",address:"Address"},f=class{constructor(e,t,r){this.stripe=e;this.config=t;this.clientSecret=r;this.elements=null;this.mountedElements=new Map;this.elementStates=new Map;if(!r)throw new i("Client secret not initialized","CONFIGURATION_ERROR")}mountPaymentElement(e){if(!this.elements){let n={clientSecret:this.clientSecret,appearance:this.config.appearance,locale:this.config.locale,fonts:this.config.fonts,paymentMethodCreation:"manual"};this.elements=this.stripe.elements(n);}if(!document.querySelector(e))throw new i(`Element not found: ${e}`,"CONFIGURATION_ERROR");let r=this.elements.create("payment",{layout:"tabs",wallets:{link:"never"}});r.mount(e),this.mountedElements.set("payment",r);}mountCardNumberElement(e){this.mountIndividualFormElement(e,"cardNumber",this.cardElementOptions("cardNumber"));}mountCardExpiryElement(e){this.mountIndividualFormElement(e,"cardExpiry",this.cardElementOptions("cardExpiry"));}mountCardCvcElement(e){this.mountIndividualFormElement(e,"cardCvc",this.cardElementOptions("cardCvc"));}mountAddressElement(e,t){this.mountIndividualFormElement(e,"address",{mode:t});}cardElementOptions(e){let{elementsConfig:t}=this.config,r={placeholder:t?.placeholders?.[e]??d.placeholders[e],style:{base:{...d.style.base,...t?.style?.base},complete:{...d.style.complete,...t?.style?.complete},empty:{...d.style.empty,...t?.style?.empty},invalid:{...d.style.invalid,...t?.style?.invalid}}};return e==="cardNumber"&&(r.showIcon=t?.showIcon??d.showIcon,r.iconStyle=t?.iconStyle??d.iconStyle),r}mountIndividualFormElement(e,t,r){if(!document.querySelector(e))throw new i(`Element not found: ${e}`,"CONFIGURATION_ERROR");let a=this.createIndividualFormElement(t,r);a.mount(e),this.mountedElements.set(t,a),this.trackElementState(t,a);}createIndividualFormElement(e,t){return this.elements||(this.elements=this.stripe.elements({appearance:this.config.appearance,locale:this.config.locale,fonts:this.config.fonts,paymentMethodCreation:"manual"})),this.elements.create(e,t)}async validate(){let e=[];for(let[t,r]of this.elementStates.entries())r.complete||e.push({field:t,message:r.error??`${v[t]??t} failed validation`});return {isValid:e.length===0,errors:e}}getElements(){return this.elements}unmountAll(){for(let e of this.mountedElements.values())e.unmount();this.mountedElements.clear(),this.elementStates.clear();}trackElementState(e,t){this.elementStates.set(e,{complete:false});let r=n=>{this.elementStates.set(e,{complete:n.complete,error:n.error?.message});};t.on("change",r);}};var h=class{constructor(){this.extensions=[];}add(e){this.extensions.push(e);}async runBeforePayment(e){let t=e;for(let r of this.extensions)r.beforePayment&&(t=await r.beforePayment(t));return t}async runAfterPayment(e){await Promise.all(this.extensions.filter(t=>t.afterPayment).map(t=>t.afterPayment(e)));}async runOnError(e){await Promise.all(this.extensions.filter(t=>t.onPaymentError).map(t=>t.onPaymentError(e)));}};var g=class{constructor(e,t,r){this.stripeAdapter=e;this.elementsManager=t;this.verapayService=r;}async process(e,t){let r=this.elementsManager.getElements();await this.validatePaymentCanProceed(r,t),await r.submit();let n=await this.stripeAdapter.createPaymentMethod(r,t.isUsingIndividualFormElements);return await this.verapayService.processPrePayment({merchantId:t.merchantId,paymentIntentId:t.paymentIntentId,paymentMethodId:n,customerData:{email:e.customerEmail,firstName:e.customerFirstName,lastName:e.customerLastName},description:e.description,metadata:e.metadata}),this.confirmPayment(n,t)}async validatePaymentCanProceed(e,t){if(!e)throw new i("Payment form not mounted","CONFIGURATION_ERROR");if(t.isUsingStripePaymentElement&&t.isUsingIndividualFormElements)throw new i("Both forms of payment form in use");if(t.isUsingIndividualFormElements){let r=await this.elementsManager.validate();if(!r.isValid)throw new i(r.errors[0].message,"VALIDATION_ERROR")}}async confirmPayment(e,t){let{clientSecret:r,isUsingStripePaymentElement:n,isUsingIndividualFormElements:a}=t,s;return n?s=await this.stripeAdapter.confirmPayment(e,r):a&&(s=await this.stripeAdapter.confirmCardPayment(e,r)),this.formatPaymentResult(s)}formatPaymentResult(e){return {success:e.paymentIntent.status==="succeeded",paymentIntentId:e.paymentIntent.id,status:e.paymentIntent.status}}};var y=class{constructor(e){this.baseUrl=e;}async initialisePayment(e){let{merchantId:t,paymentData:r}=e;try{let n=await fetch(`${this.baseUrl}/api/initialise-payment`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":"example.api.key"},body:JSON.stringify({merchantId:t,paymentData:{...r,paymentMethodType:"card"}})});if(!n.ok){let s=await n.json().catch(()=>({}));throw new i(s.error||`HTTP error! status: ${n.status}`,"CONFIGURATION_ERROR")}let a=await n.json();if(!a.clientSecret||!a.paymentIntentId)throw new i("Missing clientSecret or paymentIntentId in server response","CONFIGURATION_ERROR");return {paymentIntentId:a.paymentIntentId,clientSecret:a.clientSecret,connectAccountId:a.connectAccountId}}catch(n){throw n instanceof i?n:new i(n instanceof Error?n.message:"Unknown error occurred","CONFIGURATION_ERROR")}}async processPrePayment(e){try{let t=await fetch(`${this.baseUrl}/api/process-prepayment`,{method:"POST",headers:{"Content-Type":"application/json","x-forwarded-for":"example.ip.addr"},body:JSON.stringify({merchantId:e.merchantId,paymentIntentId:e.paymentIntentId,paymentMethodId:e.paymentMethodId,customerData:e.customerData,description:e.description,metadata:e.metadata})});if(!t.ok){let r=await t.json().catch(()=>({}));throw new i(r.error||`HTTP error! status: ${t.status}`,"CONFIGURATION_ERROR")}}catch(t){throw t instanceof i?t:new i(t instanceof Error?t.message:"Unknown error occurred","CONFIGURATION_ERROR")}}};var c=class c{constructor(e){this.stripeAdapter=null;this.elementsManager=null;this.paymentService=null;this.isUsingStripePaymentElement=false;this.isUsingIndividualFormElements=false;this.clientSecret=null;this.paymentIntentId=null;this.config=e;let t=e.enableTestMode?c.BACKEND_URL_TEST_MODE:c.BACKEND_URL;this.verapayService=new y(t),this.extensionsManager=new h;}async initialize(){this.validatePaymentInitialisation();let{clientSecret:e,paymentIntentId:t}=await this.verapayService.initialisePayment({merchantId:this.config.merchantId,paymentData:this.config.paymentData});this.clientSecret=e,this.paymentIntentId=t;let r=this.config.enableTestMode?c.STRIPE_PUBLISHABLE_KEY_TEST_MODE:c.STRIPE_PUBLISHABLE_KEY,n=await loadStripe(r);if(!n)throw new i("Failed to load Stripe","CONFIGURATION_ERROR");this.stripeAdapter=new E(n),this.elementsManager=new f(n,this.config,e),this.paymentService=new g(this.stripeAdapter,this.elementsManager,this.verapayService);}async processPayment(e){await this.ensureInitialized();let t=await this.extensionsManager.runBeforePayment(e);try{let r=await this.paymentService.process(t,{merchantId:this.config.merchantId,paymentIntentId:this.paymentIntentId,clientSecret:this.clientSecret,isUsingStripePaymentElement:this.isUsingStripePaymentElement,isUsingIndividualFormElements:this.isUsingIndividualFormElements});return await this.extensionsManager.runAfterPayment(r),r}catch(r){throw await this.extensionsManager.runOnError(r),this.handlePaymentError(r)}}async mountPaymentForm(e){await this.ensureInitialized(),this.elementsManager.mountPaymentElement(e),this.isUsingStripePaymentElement=true;}async mountCardNumber(e){await this.ensureInitialized(),this.elementsManager.mountCardNumberElement(e),this.isUsingIndividualFormElements=true;}async mountCardExpiry(e){await this.ensureInitialized(),this.elementsManager.mountCardExpiryElement(e),this.isUsingIndividualFormElements=true;}async mountCardCvc(e){await this.ensureInitialized(),this.elementsManager.mountCardCvcElement(e),this.isUsingIndividualFormElements=true;}async mountAddress(e,t){await this.ensureInitialized(),this.elementsManager.mountAddressElement(e,t),this.isUsingIndividualFormElements=true;}addExtension(e){this.extensionsManager.add(e);}async ensureInitialized(){this.stripeAdapter||await this.initialize();}validatePaymentInitialisation(){let{amount:e,currency:t,partnerFee:r}=this.config.paymentData;if(!t)throw new m("Currency is required","currency");let n=t.toUpperCase(),a=this.toMoney(e,n,"amount");if(a.isZero()||a.isNegative())throw new m("Amount must be greater than 0","amount");if(r!==void 0){let s=this.toMoney(r,n,"partnerFee");if(s.isNegative())throw new m("partnerFee cannot be negative","partnerFee");if(s.greaterThan(a))throw new m("partnerFee cannot exceed the payment amount","partnerFee")}}toMoney(e,t,r){try{return Money.fromInteger(e,t)}catch{throw new m(`${r} must be an integer in the smallest currency unit (e.g., cents for USD)`,r)}}handlePaymentError(e){return e instanceof i?e:new l(e.message||"Payment failed",e.code)}};c.STRIPE_PUBLISHABLE_KEY="pk_live_51T04b5GzlW4meYBLBylH3vfoILSU2bGysbeqiG4bLajimWO4WRv1pROt7ZUhTwVqBXvwOCHBYFUtwnZ5ZgV9vBDT00IlUeRxax",c.STRIPE_PUBLISHABLE_KEY_TEST_MODE="pk_test_51TKE9hGhFtMLMQ7kOYMRzsV7kaQhyRNFO7KDNkSvtPSZClV67x9EJkmkEiWTUsjLpkBdRIx55568T5m28g50Mraj00nhMFqAIG",c.BACKEND_URL="https://api.verapay.app",c.BACKEND_URL_TEST_MODE="https://test-api.verapay.app";var R=c;var I=class{validateCardNumber(e){let t=e.replace(/\D/g,"");if(t.length<13||t.length>19)return false;let r=0,n=false;for(let a=t.length-1;a>=0;a--){let s=parseInt(t[a],10);n&&(s*=2,s>9&&(s-=9)),r+=s,n=!n;}return r%10===0}detectCardType(e){let t=e.replace(/\D/g,"");return /^4/.test(t)?"visa":/^5[1-5]/.test(t)?"mastercard":/^3[47]/.test(t)?"amex":/^6(?:011|5)/.test(t)?"discover":"unknown"}validateExpiry(e,t){let r=new Date,n=r.getFullYear(),a=r.getMonth()+1;if(e<1||e>12)return false;let s=t<100?2e3+t:t;return !(s<n||s===n&&e<a)}validateCVC(e,t="unknown"){let r=e.replace(/\D/g,"");return t==="amex"?r.length===4:r.length===3||r.length===4}validateAll(e,t,r,n){let a=this.detectCardType(e);return {number:{isValid:this.validateCardNumber(e),cardType:a},expiry:{isValid:this.validateExpiry(t,r),month:t,year:r},cvc:{isValid:this.validateCVC(n,a),length:n.replace(/\D/g,"").length}}}};var P=class{static sanitizeCardNumber(e){return e.replace(/\D/g,"")}static formatCardNumber(e){return this.sanitizeCardNumber(e).replace(/(\d{4})/g,"$1 ").trim()}static sanitizeCVC(e){return e.replace(/\D/g,"").slice(0,4)}static sanitizeExpiry(e){let t=e.replace(/\D/g,"");return t.length===4?{month:parseInt(t.slice(0,2),10),year:parseInt(t.slice(2,4),10)}:t.length===6?{month:parseInt(t.slice(0,2),10),year:parseInt(t.slice(2,6),10)}:null}};var ue="0.0.1";
2
- export{I as CardValidator,u as ErrorFormatter,P as InputSanitizer,l as PaymentError,ue as VERSION,m as ValidationError,R as VerapayClient,i as VerapayError,y as VerapayService};//# sourceMappingURL=index.js.map
1
+ import {loadStripe}from'@stripe/stripe-js';import {Money}from'ts-money';var i=class o extends Error{constructor(e,t="PAYMENT_FAILED",r){super(e),this.name="VerapayError",this.code=t,this.details={code:t,message:e,formattedMessage:this.formatMessage(e,t),...r},Error.captureStackTrace&&Error.captureStackTrace(this,o);}formatMessage(e,t){return {VALIDATION_ERROR:"Please check your payment information and try again.",PAYMENT_FAILED:"Your payment could not be processed. Please try again.",AUTHENTICATION_FAILED:"Payment authentication failed. Please try again.",NETWORK_ERROR:"Network error. Please check your connection and try again.",STRIPE_ERROR:"Payment service error. Please try again later.",CONFIGURATION_ERROR:"Configuration error. Please contact support.",CARD_DECLINED:"Your card was declined. Please use a different payment method.",INSUFFICIENT_FUNDS:"Insufficient funds. Please use a different payment method.",EXPIRED_CARD:"Your card has expired. Please use a different payment method."}[t]||e}toJSON(){return {name:this.name,code:this.code,message:this.message,details:this.details}}};var m=class extends i{constructor(e,t,r){super(e,"VALIDATION_ERROR",{field:t,metadata:r}),this.name="ValidationError";}};var c=class o extends i{constructor(e,t,r){let n=o.mapStripeCode(t);super(e,n,{stripeCode:t,metadata:r}),this.name="PaymentError";}static mapStripeCode(e){return e?{card_declined:"CARD_DECLINED",insufficient_funds:"INSUFFICIENT_FUNDS",expired_card:"EXPIRED_CARD",incorrect_cvc:"VALIDATION_ERROR",processing_error:"PAYMENT_FAILED",authentication_failed:"AUTHENTICATION_FAILED"}[e]||"PAYMENT_FAILED":"PAYMENT_FAILED"}};var u=class{static formatForUser(e){return "formattedMessage"in e?e.formattedMessage:"details"in e&&e.details&&typeof e.details=="object"&&"formattedMessage"in e.details&&typeof e.details.formattedMessage=="string"?e.details.formattedMessage:"An unexpected error occurred. Please try again."}static formatForDeveloper(e){return "code"in e&&"message"in e?`[${e.code}] ${e.message}`:e.message||"Unknown error"}static toJSON(e){return "toJSON"in e&&typeof e.toJSON=="function"?e.toJSON():{name:e.name||"Error",message:e.message,..."code"in e&&{code:e.code},..."details"in e&&{details:e.details}}}};var h=class{constructor(e){this.stripe=e;}async confirmPayment(e,t){let r=await this.stripe.confirmPayment({clientSecret:t,confirmParams:{payment_method:e,return_url:window.location.href},redirect:"if_required"});if(r.error)throw new c(r.error.message||"Payment failed",r.error.code);return r}async confirmCardPayment(e,t){let r=await this.stripe.confirmCardPayment(t,{payment_method:e});if(r.error)throw new c(r.error.message||"Payment failed",r.error.code);return r}async createPaymentMethod(e,t=false){let r;if(!t)r=await this.stripe.createPaymentMethod({elements:e});else {let a=(await e.getElement("address",{mode:"billing"}).getValue()).value;r=await this.stripe.createPaymentMethod({type:"card",card:e.getElement("cardNumber"),billing_details:{name:a.name,address:{...a.address,line2:a.address.line2??void 0}}});}if(r.error||!r.paymentMethod)throw new c(r.error?.message||"Failed to create payment method",r.error?.code);return r.paymentMethod.id}};var p={showIcon:true,iconStyle:"solid",placeholders:{cardNumber:"1234 1234 1234 1234",cardExpiry:"MM / YY - TESTING",cardCvc:"CVC"},style:{base:{color:"#333333",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"16px","::placeholder":{color:"#aab7c4"}},complete:{color:"#333333"},empty:{},invalid:{color:"#df1b41"}}},v={cardNumber:"Card number",cardExpiry:"Expiry date",cardCvc:"CVC",address:"Address"},g=class{constructor(e,t,r){this.stripe=e;this.config=t;this.clientSecret=r;this.elements=null;this.mountedElements=new Map;this.elementStates=new Map;if(!r)throw new i("Client secret not initialized","CONFIGURATION_ERROR")}mountPaymentElement(e){if(!this.elements){let n={clientSecret:this.clientSecret,appearance:this.config.appearance,locale:this.config.locale,fonts:this.config.fonts,paymentMethodCreation:"manual"};this.elements=this.stripe.elements(n);}if(!document.querySelector(e))throw new i(`Element not found: ${e}`,"CONFIGURATION_ERROR");let r=this.elements.create("payment",{layout:"tabs",wallets:{link:"never"}});r.mount(e),this.mountedElements.set("payment",r);}mountCardNumberElement(e){this.mountIndividualFormElement(e,"cardNumber",this.cardElementOptions("cardNumber"));}mountCardExpiryElement(e){this.mountIndividualFormElement(e,"cardExpiry",this.cardElementOptions("cardExpiry"));}mountCardCvcElement(e){this.mountIndividualFormElement(e,"cardCvc",this.cardElementOptions("cardCvc"));}mountAddressElement(e,t){this.mountIndividualFormElement(e,"address",{mode:t});}cardElementOptions(e){let{elementsConfig:t}=this.config,r={placeholder:t?.placeholders?.[e]??p.placeholders[e],style:{base:{...p.style.base,...t?.style?.base},complete:{...p.style.complete,...t?.style?.complete},empty:{...p.style.empty,...t?.style?.empty},invalid:{...p.style.invalid,...t?.style?.invalid}}};return e==="cardNumber"&&(r.showIcon=t?.showIcon??p.showIcon,r.iconStyle=t?.iconStyle??p.iconStyle),r}mountIndividualFormElement(e,t,r){if(!document.querySelector(e))throw new i(`Element not found: ${e}`,"CONFIGURATION_ERROR");let a=this.createIndividualFormElement(t,r);a.mount(e),this.mountedElements.set(t,a),this.trackElementState(t,a);}createIndividualFormElement(e,t){return this.elements||(this.elements=this.stripe.elements({appearance:this.config.appearance,locale:this.config.locale,fonts:this.config.fonts,paymentMethodCreation:"manual"})),this.elements.create(e,t)}async validate(){let e=[];for(let[t,r]of this.elementStates.entries())r.complete||e.push({field:t,message:r.error??`${v[t]??t} failed validation`});return {isValid:e.length===0,errors:e}}getElements(){return this.elements}unmountAll(){for(let e of this.mountedElements.values())e.unmount();this.mountedElements.clear(),this.elementStates.clear();}trackElementState(e,t){this.elementStates.set(e,{complete:false});let r=n=>{this.elementStates.set(e,{complete:n.complete,error:n.error?.message});};t.on("change",r);}};var f=class{constructor(){this.extensions=[];}add(e){this.extensions.push(e);}async runBeforePayment(e){let t=e;for(let r of this.extensions)r.beforePayment&&(t=await r.beforePayment(t));return t}async runAfterPayment(e){await Promise.all(this.extensions.filter(t=>t.afterPayment).map(t=>t.afterPayment(e)));}async runOnError(e){await Promise.all(this.extensions.filter(t=>t.onPaymentError).map(t=>t.onPaymentError(e)));}};var E=class{constructor(e,t,r){this.stripeAdapter=e;this.elementsManager=t;this.verapayService=r;}async process(e,t){let r=this.elementsManager.getElements();await this.validatePaymentCanProceed(r,t),await r.submit();let n=await this.stripeAdapter.createPaymentMethod(r,t.isUsingIndividualFormElements);return await this.verapayService.processPrePayment({merchantId:t.merchantId,paymentIntentId:t.paymentIntentId,paymentMethodId:n,amount:t.amount,currency:t.currency,customerData:{email:e.customerEmail,firstName:e.customerFirstName,lastName:e.customerLastName},description:e.description,metadata:e.metadata}),this.confirmPayment(n,t)}async validatePaymentCanProceed(e,t){if(!e)throw new i("Payment form not mounted","CONFIGURATION_ERROR");if(t.isUsingStripePaymentElement&&t.isUsingIndividualFormElements)throw new i("Both forms of payment form in use");if(t.isUsingIndividualFormElements){let r=await this.elementsManager.validate();if(!r.isValid)throw new i(r.errors[0].message,"VALIDATION_ERROR")}}async confirmPayment(e,t){let{clientSecret:r,isUsingStripePaymentElement:n,isUsingIndividualFormElements:a}=t,s;return n?s=await this.stripeAdapter.confirmPayment(e,r):a&&(s=await this.stripeAdapter.confirmCardPayment(e,r)),this.formatPaymentResult(s)}formatPaymentResult(e){return {success:e.paymentIntent.status==="succeeded",paymentIntentId:e.paymentIntent.id,status:e.paymentIntent.status}}};var y=class{constructor(e,t){this.baseUrl=e,this.apiKey=t;}async initialisePayment(e){let{merchantId:t,paymentData:r}=e;try{let n=await fetch(`${this.baseUrl}/api/initialise-payment`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify({merchantId:t,paymentData:{...r,paymentMethodType:"card"}})});if(!n.ok){let s=await n.json().catch(()=>({}));throw new i(this.extractErrorMessage(s,n.status),"CONFIGURATION_ERROR")}let a=await n.json();if(!a.clientSecret||!a.paymentIntentId)throw new i("Missing clientSecret or paymentIntentId in server response","CONFIGURATION_ERROR");return {paymentIntentId:a.paymentIntentId,clientSecret:a.clientSecret,connectAccountId:a.connectAccountId,stripePublishableKey:a.stripePublishableKey}}catch(n){throw n instanceof i?n:new i(n instanceof Error?n.message:"Unknown error occurred","CONFIGURATION_ERROR")}}async processPrePayment(e){try{let t=await fetch(`${this.baseUrl}/api/process-prepayment`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.apiKey},body:JSON.stringify({merchantId:e.merchantId,paymentIntentId:e.paymentIntentId,paymentMethodId:e.paymentMethodId,amount:e.amount,currency:e.currency,customerData:e.customerData,description:e.description,metadata:e.metadata})});if(!t.ok){let r=await t.json().catch(()=>({}));throw new i(this.extractErrorMessage(r,t.status),"CONFIGURATION_ERROR")}}catch(t){throw t instanceof i?t:new i(t instanceof Error?t.message:"Unknown error occurred","CONFIGURATION_ERROR")}}extractErrorMessage(e,t){if(!e||typeof e!="object")return `HTTP error! status: ${t}`;let r=e,n=[r.error,r.message,r.details];for(let a of n){if(typeof a=="string"&&a.trim().length>0)return a;if(a&&typeof a=="object")try{return JSON.stringify(a)}catch{}}return `HTTP error! status: ${t}`}};var d=class d{constructor(e){this.stripeAdapter=null;this.elementsManager=null;this.paymentService=null;this.isUsingStripePaymentElement=false;this.isUsingIndividualFormElements=false;this.clientSecret=null;this.paymentIntentId=null;if(!e.apiKey)throw new i("apiKey is required. Pass your Verapay publishable key (vpy_pk_test_... or vpy_pk_live_...) when constructing VerapayClient.","CONFIGURATION_ERROR");this.config=e,!this.config.apiKey.includes("_pk_")&&typeof window<"u"&&console.warn("Verapay Security Warning: You are using a Secret Key in a frontend environment. Please use a Publishable Key (vpy_pk_...) instead.");let t=this.config.apiUrlOverride||(this.isTestKey()?d.BACKEND_URL_TEST_MODE:d.BACKEND_URL);this.verapayService=new y(t,this.config.apiKey),this.extensionsManager=new f;}async initialize(){this.validatePaymentInitialisation();let{clientSecret:e,paymentIntentId:t,stripePublishableKey:r}=await this.verapayService.initialisePayment({merchantId:this.config.merchantId??"",paymentData:this.config.paymentData});this.clientSecret=e,this.paymentIntentId=t;let n=await loadStripe(r);if(!n)throw new i("Failed to load Stripe","CONFIGURATION_ERROR");this.stripeAdapter=new h(n),this.elementsManager=new g(n,this.config,e),this.paymentService=new E(this.stripeAdapter,this.elementsManager,this.verapayService);}async processPayment(e){await this.ensureInitialized();let t=await this.extensionsManager.runBeforePayment(e);try{let r=await this.paymentService.process(t,{merchantId:this.config.merchantId??"",paymentIntentId:this.paymentIntentId,clientSecret:this.clientSecret,amount:this.config.paymentData.amount,currency:this.config.paymentData.currency,isUsingStripePaymentElement:this.isUsingStripePaymentElement,isUsingIndividualFormElements:this.isUsingIndividualFormElements});return await this.extensionsManager.runAfterPayment(r),r}catch(r){throw await this.extensionsManager.runOnError(r),this.handlePaymentError(r)}}async mountPaymentForm(e){await this.ensureInitialized(),this.elementsManager.mountPaymentElement(e),this.isUsingStripePaymentElement=true;}async mountCardNumber(e){await this.ensureInitialized(),this.elementsManager.mountCardNumberElement(e),this.isUsingIndividualFormElements=true;}async mountCardExpiry(e){await this.ensureInitialized(),this.elementsManager.mountCardExpiryElement(e),this.isUsingIndividualFormElements=true;}async mountCardCvc(e){await this.ensureInitialized(),this.elementsManager.mountCardCvcElement(e),this.isUsingIndividualFormElements=true;}async mountAddress(e,t){await this.ensureInitialized(),this.elementsManager.mountAddressElement(e,t),this.isUsingIndividualFormElements=true;}addExtension(e){this.extensionsManager.add(e);}async ensureInitialized(){this.stripeAdapter||await this.initialize();}validatePaymentInitialisation(){let{amount:e,currency:t,partnerFee:r}=this.config.paymentData;if(!t)throw new m("Currency is required","currency");let n=t.toUpperCase(),a=this.toMoney(e,n,"amount");if(a.isZero()||a.isNegative())throw new m("Amount must be greater than 0","amount");if(r!==void 0){let s=this.toMoney(r,n,"partnerFee");if(s.isNegative())throw new m("partnerFee cannot be negative","partnerFee");if(s.greaterThan(a))throw new m("partnerFee cannot exceed the payment amount","partnerFee")}}toMoney(e,t,r){try{return Money.fromInteger(e,t)}catch{throw new m(`${r} must be an integer in the smallest currency unit (e.g., cents for USD)`,r)}}isTestKey(){return this.config.apiKey.startsWith("vpy_pk_test_")||this.config.apiKey.startsWith("vpy_test_")}handlePaymentError(e){return e instanceof i?e:new c(e.message||"Payment failed",e.code)}};d.BACKEND_URL="https://api.verapay.app",d.BACKEND_URL_TEST_MODE="https://test-api.verapay.app";var R=d;var I=class{validateCardNumber(e){let t=e.replace(/\D/g,"");if(t.length<13||t.length>19)return false;let r=0,n=false;for(let a=t.length-1;a>=0;a--){let s=parseInt(t[a],10);n&&(s*=2,s>9&&(s-=9)),r+=s,n=!n;}return r%10===0}detectCardType(e){let t=e.replace(/\D/g,"");return /^4/.test(t)?"visa":/^5[1-5]/.test(t)?"mastercard":/^3[47]/.test(t)?"amex":/^6(?:011|5)/.test(t)?"discover":"unknown"}validateExpiry(e,t){let r=new Date,n=r.getFullYear(),a=r.getMonth()+1;if(e<1||e>12)return false;let s=t<100?2e3+t:t;return !(s<n||s===n&&e<a)}validateCVC(e,t="unknown"){let r=e.replace(/\D/g,"");return t==="amex"?r.length===4:r.length===3||r.length===4}validateAll(e,t,r,n){let a=this.detectCardType(e);return {number:{isValid:this.validateCardNumber(e),cardType:a},expiry:{isValid:this.validateExpiry(t,r),month:t,year:r},cvc:{isValid:this.validateCVC(n,a),length:n.replace(/\D/g,"").length}}}};var P=class{static sanitizeCardNumber(e){return e.replace(/\D/g,"")}static formatCardNumber(e){return this.sanitizeCardNumber(e).replace(/(\d{4})/g,"$1 ").trim()}static sanitizeCVC(e){return e.replace(/\D/g,"").slice(0,4)}static sanitizeExpiry(e){let t=e.replace(/\D/g,"");return t.length===4?{month:parseInt(t.slice(0,2),10),year:parseInt(t.slice(2,4),10)}:t.length===6?{month:parseInt(t.slice(0,2),10),year:parseInt(t.slice(2,6),10)}:null}};var ue="1.1.0";
2
+ export{I as CardValidator,u as ErrorFormatter,P as InputSanitizer,c as PaymentError,ue as VERSION,m as ValidationError,R as VerapayClient,i as VerapayError,y as VerapayService};//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors/verapay-error.ts","../src/errors/validation-error.ts","../src/errors/payment-error.ts","../src/errors/error-formatter.ts","../src/client/stripe-adapter.ts","../src/client/elements-manager.ts","../src/client/payment-extensions-manager.ts","../src/services/payment-service.ts","../src/services/verapay-service.ts","../src/client/verapay-client.ts","../src/validation/card-validator.ts","../src/validation/input-sanitizer.ts","../src/index.ts"],"names":["VerapayError","_VerapayError","message","code","details","ValidationError","field","metadata","PaymentError","_PaymentError","stripeCode","ErrorFormatter","error","StripeAdapter","stripe","paymentMethodId","clientSecret","result","elements","isUsingIndividualFormElements","address","DEFAULT_CARD_ELEMENT_CONFIG","FIELD_LABELS","ElementsManager","config","selector","elementsConfig","element","mode","fieldType","options","formFieldType","errors","state","handleElementChange","event","PaymentExtensionsManager","extension","request","modifiedRequest","ext","PaymentService","stripeAdapter","elementsManager","verapayService","context","validation","isUsingStripePaymentElement","VerapayService","baseUrl","merchantId","paymentData","response","errorData","data","_VerapayClient","backendUrl","paymentIntentId","stripeKey","loadStripe","paymentResult","amount","currency","partnerFee","uppercaseCurrency","paymentAmount","partnerFeeAmount","value","fieldName","Money","VerapayClient","CardValidator","cardNumber","cleaned","sum","isEven","i","digit","month","year","now","currentYear","currentMonth","fullYear","cvc","cardType","expiryMonth","expiryYear","InputSanitizer","input","VERSION"],"mappings":"wEAGO,IAAMA,CAAAA,CAAN,MAAMC,CAAAA,SAAqB,KAAM,CAItC,WAAA,CACEC,CAAAA,CACAC,CAAAA,CAAAA,gBAAAA,CACAC,CAAAA,CACA,CACA,KAAA,CAAMF,CAAO,CAAA,CACb,IAAA,CAAK,IAAA,CAAO,cAAA,CACZ,IAAA,CAAK,IAAA,CAAOC,CAAAA,CACZ,IAAA,CAAK,OAAA,CAAU,CACb,IAAA,CAAAA,CAAAA,CACA,OAAA,CAAAD,CAAAA,CACA,gBAAA,CAAkB,IAAA,CAAK,aAAA,CAAcA,CAAAA,CAASC,CAAI,CAAA,CAClD,GAAGC,CACL,CAAA,CAEI,KAAA,CAAM,iBAAA,EACR,KAAA,CAAM,kBAAkB,IAAA,CAAMH,CAAY,EAE9C,CAEQ,aAAA,CAAcC,CAAAA,CAAiBC,CAAAA,CAAyB,CAsB9D,OArB8C,CAC3C,gBAAA,CACC,sDAAA,CACD,cAAA,CACC,wDAAA,CACD,qBAAA,CACC,kDAAA,CACD,aAAA,CACC,6DACD,YAAA,CACC,gDAAA,CACD,mBAAA,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ACd,CACL,KAAA,CAAO,SAASA,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,CAAA,CACvC,IAAA,CAAM,SAASA,CAAAA,CAAQ,KAAA,CAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,CACxC,CAAA,CACSA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CACrB,CACL,KAAA,CAAO,QAAA,CAASA,CAAAA,CAAQ,KAAA,CAAM,EAAG,CAAC,CAAA,CAAG,EAAE,CAAA,CACvC,IAAA,CAAM,QAAA,CAASA,CAAAA,CAAQ,KAAA,CAAM,EAAG,CAAC,CAAA,CAAG,EAAE,CACxC,CAAA,CAGK,IACT,CACF,MCGaiB,EAAAA,CAAU","file":"index.js","sourcesContent":["import type { ErrorDetails } from '../types';\nimport { ErrorCode } from '../types';\n\nexport class VerapayError extends Error {\n public readonly code: ErrorCode;\n public readonly details: ErrorDetails;\n\n constructor(\n message: string,\n code: ErrorCode = ErrorCode.PAYMENT_FAILED,\n details?: Partial<ErrorDetails>\n ) {\n super(message);\n this.name = 'VerapayError';\n this.code = code;\n this.details = {\n code,\n message,\n formattedMessage: this.formatMessage(message, code),\n ...details,\n };\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, VerapayError);\n }\n }\n\n private formatMessage(message: string, code: ErrorCode): string {\n const messageMap: Record<ErrorCode, string> = {\n [ErrorCode.VALIDATION_ERROR]:\n 'Please check your payment information and try again.',\n [ErrorCode.PAYMENT_FAILED]:\n 'Your payment could not be processed. Please try again.',\n [ErrorCode.AUTHENTICATION_FAILED]:\n 'Payment authentication failed. Please try again.',\n [ErrorCode.NETWORK_ERROR]:\n 'Network error. Please check your connection and try again.',\n [ErrorCode.STRIPE_ERROR]:\n 'Payment service error. Please try again later.',\n [ErrorCode.CONFIGURATION_ERROR]:\n 'Configuration error. Please contact support.',\n [ErrorCode.CARD_DECLINED]:\n 'Your card was declined. Please use a different payment method.',\n [ErrorCode.INSUFFICIENT_FUNDS]:\n 'Insufficient funds. Please use a different payment method.',\n [ErrorCode.EXPIRED_CARD]:\n 'Your card has expired. Please use a different payment method.',\n };\n\n return messageMap[code] || message;\n }\n\n toJSON() {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n details: this.details,\n };\n }\n}\n","import { VerapayError } from './verapay-error';\nimport { ErrorCode } from '../types';\n\nexport class ValidationError extends VerapayError {\n constructor(message: string, field?: string, metadata?: Record<string, any>) {\n super(message, ErrorCode.VALIDATION_ERROR, {\n field,\n metadata,\n });\n this.name = 'ValidationError';\n }\n}\n","import { VerapayError } from './verapay-error';\nimport { ErrorCode } from '../types';\n\nexport class PaymentError extends VerapayError {\n constructor(\n message: string,\n stripeCode?: string,\n metadata?: Record<string, any>\n ) {\n const code = PaymentError.mapStripeCode(stripeCode);\n super(message, code, {\n stripeCode,\n metadata,\n });\n this.name = 'PaymentError';\n }\n\n private static mapStripeCode(stripeCode?: string): ErrorCode {\n if (!stripeCode) return ErrorCode.PAYMENT_FAILED;\n\n const codeMap: Record<string, ErrorCode> = {\n card_declined: ErrorCode.CARD_DECLINED,\n insufficient_funds: ErrorCode.INSUFFICIENT_FUNDS,\n expired_card: ErrorCode.EXPIRED_CARD,\n incorrect_cvc: ErrorCode.VALIDATION_ERROR,\n processing_error: ErrorCode.PAYMENT_FAILED,\n authentication_failed: ErrorCode.AUTHENTICATION_FAILED,\n };\n\n return codeMap[stripeCode] || ErrorCode.PAYMENT_FAILED;\n }\n}\n","import type { ErrorDetails } from '../types';\n\nexport class ErrorFormatter {\n static formatForUser(error: Error | ErrorDetails): string {\n if ('formattedMessage' in error) {\n return error.formattedMessage;\n }\n if (\n 'details' in error &&\n error.details &&\n typeof error.details === 'object' &&\n 'formattedMessage' in error.details &&\n typeof error.details.formattedMessage === 'string'\n ) {\n return error.details.formattedMessage;\n }\n return 'An unexpected error occurred. Please try again.';\n }\n\n static formatForDeveloper(error: Error | ErrorDetails): string {\n if ('code' in error && 'message' in error) {\n return `[${error.code}] ${error.message}`;\n }\n return error.message || 'Unknown error';\n }\n\n static toJSON(error: Error | ErrorDetails): Record<string, any> {\n if ('toJSON' in error && typeof error.toJSON === 'function') {\n return error.toJSON();\n }\n\n return {\n name: (error as Error).name || 'Error',\n message: error.message,\n ...('code' in error && { code: error.code }),\n ...('details' in error && { details: error.details }),\n };\n }\n}\n","import type { PaymentIntent, Stripe, StripeElements } from '@stripe/stripe-js';\nimport { PaymentError } from '../errors';\n\nexport class StripeAdapter {\n constructor(private stripe: Stripe) {}\n\n async confirmPayment(\n paymentMethodId: string,\n clientSecret: string\n ): Promise<{ paymentIntent: PaymentIntent }> {\n const result = await this.stripe.confirmPayment({\n clientSecret,\n confirmParams: {\n payment_method: paymentMethodId,\n return_url: window.location.href,\n },\n redirect: 'if_required',\n });\n\n if (result.error) {\n throw new PaymentError(\n result.error.message || 'Payment failed',\n result.error.code\n );\n }\n\n return result as { paymentIntent: PaymentIntent };\n }\n\n async confirmCardPayment(\n paymentMethodId: string,\n clientSecret: string\n ): Promise<{ paymentIntent: PaymentIntent }> {\n const result = await this.stripe.confirmCardPayment(clientSecret, {\n payment_method: paymentMethodId,\n });\n\n if (result.error) {\n throw new PaymentError(\n result.error.message || 'Payment failed',\n result.error.code\n );\n }\n\n return result as { paymentIntent: PaymentIntent };\n }\n\n async createPaymentMethod(\n elements: StripeElements,\n isUsingIndividualFormElements: boolean = false\n ): Promise<string> {\n let result;\n\n if (!isUsingIndividualFormElements) {\n result = await this.stripe.createPaymentMethod({\n elements,\n });\n } else {\n // @ts-ignore - Stripe types don't include mode parameter for getElement\n const addressElement = await elements.getElement('address', { mode: 'billing' })!.getValue();\n const address = addressElement!.value;\n\n result = await this.stripe.createPaymentMethod({\n type: 'card',\n card: elements.getElement('cardNumber')!,\n billing_details: {\n name: address.name,\n address: {\n ...address.address,\n line2: address.address.line2 ?? undefined,\n },\n },\n });\n }\n\n if (result.error || !result.paymentMethod) {\n throw new PaymentError(\n result.error?.message || 'Failed to create payment method',\n result.error?.code\n );\n }\n\n return result.paymentMethod.id;\n }\n}\n","import type {\n Stripe,\n StripeElements,\n StripeElement,\n StripePaymentElement,\n StripeCardNumberElement,\n PaymentWalletsOption,\n} from '@stripe/stripe-js';\nimport type { VerapayConfig, ValidationError, ValidationResult } from '../types';\nimport { VerapayError, ErrorCode } from '../errors';\n\ntype ElementState = { complete: boolean; error?: string }\n\nconst DEFAULT_CARD_ELEMENT_CONFIG = {\n showIcon: true,\n iconStyle: 'solid' as const,\n placeholders: {\n cardNumber: '1234 1234 1234 1234',\n cardExpiry: 'MM / YY - TESTING',\n cardCvc: 'CVC',\n },\n style: {\n base: {\n color: '#333333',\n fontFamily: 'system-ui, -apple-system, sans-serif',\n fontSize: '16px',\n '::placeholder': { color: '#aab7c4' },\n },\n complete: {\n color: '#333333',\n },\n empty: {},\n invalid: {\n color: '#df1b41',\n },\n },\n}\n\nconst FIELD_LABELS: Record<string, string> = {\n cardNumber: 'Card number',\n cardExpiry: 'Expiry date',\n cardCvc: 'CVC',\n address: 'Address',\n}\n\nexport class ElementsManager {\n private elements: StripeElements | null = null;\n private mountedElements: Map<string, StripeElement> = new Map();\n private elementStates: Map<string, ElementState> = new Map();\n\n constructor(\n private stripe: Stripe,\n private config: VerapayConfig,\n private clientSecret: string\n ) {\n if (!clientSecret) {\n throw new VerapayError(\n 'Client secret not initialized',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n mountPaymentElement(selector: string): void {\n if (!this.elements) {\n const elementsConfig = {\n clientSecret: this.clientSecret,\n appearance: this.config.appearance,\n locale: this.config.locale,\n fonts: this.config.fonts,\n paymentMethodCreation: 'manual',\n };\n\n this.elements = this.stripe.elements(elementsConfig);\n }\n\n const container = document.querySelector(selector);\n\n if (!container) {\n throw new VerapayError(\n `Element not found: ${selector}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const element = this.elements.create('payment', {\n layout: 'tabs',\n wallets: { link: 'never' } as unknown as PaymentWalletsOption,\n }) as StripePaymentElement;\n\n element.mount(selector);\n this.mountedElements.set('payment', element);\n }\n\n mountCardNumberElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardNumber', this.cardElementOptions('cardNumber'));\n }\n\n mountCardExpiryElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardExpiry', this.cardElementOptions('cardExpiry'));\n }\n\n mountCardCvcElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardCvc', this.cardElementOptions('cardCvc'));\n }\n\n mountAddressElement(selector: string, mode: 'billing' | 'shipping'): void {\n this.mountIndividualFormElement(selector, 'address', { mode });\n }\n\n private cardElementOptions(fieldType: 'cardNumber' | 'cardExpiry' | 'cardCvc'): Record<string, unknown> {\n const { elementsConfig } = this.config;\n const options: Record<string, unknown> = {\n placeholder: elementsConfig?.placeholders?.[fieldType] ?? DEFAULT_CARD_ELEMENT_CONFIG.placeholders[fieldType],\n style: {\n base: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.base, ...elementsConfig?.style?.base },\n complete: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.complete, ...elementsConfig?.style?.complete },\n empty: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.empty, ...elementsConfig?.style?.empty },\n invalid: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.invalid, ...elementsConfig?.style?.invalid },\n },\n };\n\n if (fieldType === 'cardNumber') {\n options.showIcon = elementsConfig?.showIcon ?? DEFAULT_CARD_ELEMENT_CONFIG.showIcon;\n options.iconStyle = elementsConfig?.iconStyle ?? DEFAULT_CARD_ELEMENT_CONFIG.iconStyle;\n }\n\n return options;\n }\n\n private mountIndividualFormElement(selector: string, formFieldType: 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address', options?: Record<string, unknown>) {\n const container = document.querySelector(selector);\n\n if (!container) {\n throw new VerapayError(\n `Element not found: ${selector}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const element = this.createIndividualFormElement(formFieldType, options) as StripeCardNumberElement;\n element.mount(selector);\n\n this.mountedElements.set(formFieldType, element);\n this.trackElementState(formFieldType, element);\n }\n\n private createIndividualFormElement(\n formFieldType: any,\n options?: Record<string, unknown>\n ): StripeElement {\n if (!this.elements) {\n // For individual card elements, don't pass clientSecret\n // It's only needed when creating Payment Element or confirming payment\n this.elements = this.stripe.elements({\n appearance: this.config.appearance,\n locale: this.config.locale,\n fonts: this.config.fonts,\n paymentMethodCreation: 'manual',\n });\n }\n\n return this.elements.create(formFieldType, options);\n }\n\n async validate(): Promise<ValidationResult> {\n const errors: ValidationError[] = []\n\n for (const [field, state] of this.elementStates.entries()) {\n if (!state.complete) {\n errors.push({\n field,\n message: state.error ?? `${FIELD_LABELS[field] ?? field} failed validation`,\n })\n }\n }\n\n return { isValid: errors.length === 0, errors }\n }\n\n getElements(): StripeElements | null {\n return this.elements;\n }\n\n unmountAll(): void {\n for (const element of this.mountedElements.values()) {\n element.unmount();\n }\n this.mountedElements.clear();\n this.elementStates.clear();\n }\n\n private trackElementState(field: string, element: StripeElement): void {\n this.elementStates.set(field, { complete: false })\n\n const handleElementChange = (event: { complete: boolean; error?: { message: string } }) => {\n this.elementStates.set(field, { complete: event.complete, error: event.error?.message })\n };\n\n (element as any).on('change', handleElementChange)\n }\n}\n","import type { ProcessPaymentRequest, PaymentResult } from '../types'\nimport type { PaymentExtension } from '../extensions'\n\nexport class PaymentExtensionsManager {\n private extensions: PaymentExtension[] = []\n\n add(extension: PaymentExtension): void {\n this.extensions.push(extension)\n }\n\n async runBeforePayment(request: ProcessPaymentRequest): Promise<ProcessPaymentRequest> {\n let modifiedRequest = request\n for (const ext of this.extensions) {\n if (ext.beforePayment) {\n modifiedRequest = await ext.beforePayment(modifiedRequest)\n }\n }\n return modifiedRequest\n }\n\n async runAfterPayment(result: PaymentResult): Promise<void> {\n await Promise.all(\n this.extensions\n .filter((ext) => ext.afterPayment)\n .map((ext) => ext.afterPayment!(result)),\n )\n }\n\n async runOnError(error: Error): Promise<void> {\n await Promise.all(\n this.extensions\n .filter((ext) => ext.onPaymentError)\n .map((ext) => ext.onPaymentError!(error)),\n )\n }\n}\n","import { StripeAdapter } from '../client/stripe-adapter'\nimport { ElementsManager } from '../client/elements-manager'\nimport { ErrorCode, VerapayError } from '../errors'\nimport { VerapayService } from './verapay-service'\nimport type { ProcessPaymentRequest, PaymentResult } from '../types'\nimport { StripeElements } from '@stripe/stripe-js';\n\nexport interface ProcessPaymentContext {\n merchantId: string\n paymentIntentId: string\n clientSecret: string\n isUsingStripePaymentElement: boolean\n isUsingIndividualFormElements: boolean\n}\n\nexport class PaymentService {\n constructor(\n private stripeAdapter: StripeAdapter,\n private elementsManager: ElementsManager,\n private verapayService: VerapayService,\n ) {}\n\n async process(request: ProcessPaymentRequest, context: ProcessPaymentContext): Promise<PaymentResult> {\n const elements = this.elementsManager.getElements()\n\n await this.validatePaymentCanProceed(elements, context);\n\n await elements!.submit()\n\n const paymentMethodId = await this.stripeAdapter.createPaymentMethod(\n elements!,\n context.isUsingIndividualFormElements,\n )\n\n await this.verapayService.processPrePayment({\n merchantId: context.merchantId,\n paymentIntentId: context.paymentIntentId,\n paymentMethodId,\n customerData: {\n email: request.customerEmail,\n firstName: request.customerFirstName,\n lastName: request.customerLastName,\n },\n description: request.description,\n metadata: request.metadata,\n })\n\n return this.confirmPayment(paymentMethodId, context)\n }\n\n private async validatePaymentCanProceed(elements: StripeElements | null, context: ProcessPaymentContext) {\n if (!elements) {\n throw new VerapayError('Payment form not mounted', ErrorCode.CONFIGURATION_ERROR)\n }\n\n if (context.isUsingStripePaymentElement && context.isUsingIndividualFormElements) {\n throw new VerapayError('Both forms of payment form in use');\n }\n\n if (context.isUsingIndividualFormElements) {\n const validation = await this.elementsManager.validate()\n if (!validation.isValid) {\n throw new VerapayError(validation.errors[0].message, ErrorCode.VALIDATION_ERROR)\n }\n }\n }\n\n private async confirmPayment(\n paymentMethodId: string,\n context: ProcessPaymentContext,\n ): Promise<PaymentResult> {\n const { clientSecret, isUsingStripePaymentElement, isUsingIndividualFormElements } = context\n\n let result\n\n if (isUsingStripePaymentElement) {\n result = await this.stripeAdapter.confirmPayment(paymentMethodId, clientSecret)\n } else if (isUsingIndividualFormElements) {\n result = await this.stripeAdapter.confirmCardPayment(paymentMethodId, clientSecret)\n }\n\n return this.formatPaymentResult(result)\n }\n\n private formatPaymentResult(result: any): PaymentResult {\n return {\n success: result.paymentIntent.status === 'succeeded',\n paymentIntentId: result.paymentIntent.id,\n status: result.paymentIntent.status,\n }\n }\n}\n","import { ErrorCode, VerapayError } from '../errors';\nimport { PaymentData } from '../types';\n\nexport interface InitialisePaymentRequest {\n merchantId: string;\n paymentData: PaymentData;\n}\n\nexport interface InitialisePaymentResponse {\n paymentIntentId: string;\n clientSecret: string;\n connectAccountId: string;\n}\n\nexport interface ProcessPrePaymentRequest {\n merchantId: string;\n paymentIntentId: string;\n paymentMethodId: string;\n customerData: Record<string, any>;\n description?: string;\n metadata?: Record<string, string>;\n}\n\nexport class VerapayService {\n private readonly baseUrl: string;\n\n constructor(baseUrl: string) {\n this.baseUrl = baseUrl;\n }\n\n async initialisePayment(\n request: InitialisePaymentRequest\n ): Promise<InitialisePaymentResponse> {\n const { merchantId, paymentData } = request;\n\n try {\n const response = await fetch(`${this.baseUrl}/api/initialise-payment`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': 'example.api.key',\n },\n body: JSON.stringify({\n merchantId,\n paymentData: { ...paymentData, paymentMethodType: 'card' },\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n throw new VerapayError(\n errorData.error || `HTTP error! status: ${response.status}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const data = await response.json();\n\n if (!data.clientSecret || !data.paymentIntentId) {\n throw new VerapayError(\n 'Missing clientSecret or paymentIntentId in server response',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n return {\n paymentIntentId: data.paymentIntentId,\n clientSecret: data.clientSecret,\n connectAccountId: data.connectAccountId,\n };\n } catch (error) {\n if (error instanceof VerapayError) {\n throw error;\n }\n throw new VerapayError(\n error instanceof Error ? error.message : 'Unknown error occurred',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n async processPrePayment(request: ProcessPrePaymentRequest): Promise<void> {\n try {\n const response = await fetch(`${this.baseUrl}/api/process-prepayment`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-forwarded-for': 'example.ip.addr',\n },\n body: JSON.stringify({\n merchantId: request.merchantId,\n paymentIntentId: request.paymentIntentId,\n paymentMethodId: request.paymentMethodId,\n customerData: request.customerData,\n description: request.description,\n metadata: request.metadata,\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n throw new VerapayError(\n errorData.error || `HTTP error! status: ${response.status}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n } catch (error) {\n if (error instanceof VerapayError) {\n throw error;\n }\n throw new VerapayError(\n error instanceof Error ? error.message : 'Unknown error occurred',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n}\n","import { loadStripe } from '@stripe/stripe-js';\nimport { Money } from 'ts-money';\nimport { StripeAdapter } from './stripe-adapter';\nimport { ElementsManager } from './elements-manager';\nimport type { PaymentExtension } from '../extensions';\nimport { PaymentExtensionsManager } from './payment-extensions-manager';\nimport { PaymentService } from '../services/payment-service';\nimport {\n ErrorCode,\n VerapayError,\n PaymentError,\n ValidationError,\n} from '../errors';\nimport { VerapayService } from '../services/verapay-service';\nimport type {\n VerapayConfig,\n ProcessPaymentRequest,\n PaymentResult,\n} from '../types';\n\nexport class VerapayClient {\n private static readonly STRIPE_PUBLISHABLE_KEY =\n 'pk_live_51T04b5GzlW4meYBLBylH3vfoILSU2bGysbeqiG4bLajimWO4WRv1pROt7ZUhTwVqBXvwOCHBYFUtwnZ5ZgV9vBDT00IlUeRxax';\n private static readonly STRIPE_PUBLISHABLE_KEY_TEST_MODE =\n 'pk_test_51TKE9hGhFtMLMQ7kOYMRzsV7kaQhyRNFO7KDNkSvtPSZClV67x9EJkmkEiWTUsjLpkBdRIx55568T5m28g50Mraj00nhMFqAIG';\n\n private static readonly BACKEND_URL = 'https://api.verapay.app';\n private static readonly BACKEND_URL_TEST_MODE = 'https://test-api.verapay.app';\n\n private config: VerapayConfig;\n private verapayService: VerapayService;\n private extensionsManager: PaymentExtensionsManager;\n\n private stripeAdapter: StripeAdapter | null = null;\n private elementsManager: ElementsManager | null = null;\n private paymentService: PaymentService | null = null;\n\n private isUsingStripePaymentElement: boolean = false;\n private isUsingIndividualFormElements: boolean = false;\n\n private clientSecret: string | null = null;\n private paymentIntentId: string | null = null;\n\n constructor(config: VerapayConfig) {\n this.config = config;\n\n const backendUrl = config.enableTestMode\n ? VerapayClient.BACKEND_URL_TEST_MODE\n : VerapayClient.BACKEND_URL;\n\n this.verapayService = new VerapayService(backendUrl);\n this.extensionsManager = new PaymentExtensionsManager();\n }\n\n async initialize(): Promise<void> {\n this.validatePaymentInitialisation()\n\n const { clientSecret, paymentIntentId } =\n await this.verapayService.initialisePayment({\n merchantId: this.config.merchantId,\n paymentData: this.config.paymentData\n });\n\n this.clientSecret = clientSecret;\n this.paymentIntentId = paymentIntentId;\n\n const stripeKey = this.config.enableTestMode\n ? VerapayClient.STRIPE_PUBLISHABLE_KEY_TEST_MODE\n : VerapayClient.STRIPE_PUBLISHABLE_KEY;\n\n const stripe = await loadStripe(stripeKey);\n\n if (!stripe) {\n throw new VerapayError(\n 'Failed to load Stripe',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n this.stripeAdapter = new StripeAdapter(stripe);\n this.elementsManager = new ElementsManager(\n stripe,\n this.config,\n clientSecret\n );\n this.paymentService = new PaymentService(\n this.stripeAdapter,\n this.elementsManager,\n this.verapayService\n );\n }\n\n async processPayment(request: ProcessPaymentRequest): Promise<PaymentResult> {\n await this.ensureInitialized();\n\n let modifiedRequest =\n await this.extensionsManager.runBeforePayment(request);\n\n try {\n const paymentResult = await this.paymentService!.process(\n modifiedRequest,\n {\n merchantId: this.config.merchantId,\n paymentIntentId: this.paymentIntentId!,\n clientSecret: this.clientSecret!,\n isUsingStripePaymentElement: this.isUsingStripePaymentElement,\n isUsingIndividualFormElements: this.isUsingIndividualFormElements,\n }\n );\n\n await this.extensionsManager.runAfterPayment(paymentResult);\n\n return paymentResult;\n } catch (error) {\n await this.extensionsManager.runOnError(error as Error);\n throw this.handlePaymentError(error);\n }\n }\n\n async mountPaymentForm(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountPaymentElement(selector);\n this.isUsingStripePaymentElement = true;\n }\n\n async mountCardNumber(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardNumberElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountCardExpiry(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardExpiryElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountCardCvc(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardCvcElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountAddress(\n selector: string,\n mode: 'billing' | 'shipping'\n ): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountAddressElement(selector, mode);\n this.isUsingIndividualFormElements = true;\n }\n\n addExtension(extension: PaymentExtension): void {\n this.extensionsManager.add(extension);\n }\n\n private async ensureInitialized(): Promise<void> {\n if (!this.stripeAdapter) {\n await this.initialize();\n }\n }\n\n private validatePaymentInitialisation(): void {\n const { amount, currency, partnerFee } = this.config.paymentData;\n\n if (!currency) {\n throw new ValidationError('Currency is required', 'currency');\n }\n\n const uppercaseCurrency = currency.toUpperCase();\n\n const paymentAmount = this.toMoney(amount, uppercaseCurrency, 'amount');\n\n if (paymentAmount.isZero() || paymentAmount.isNegative()) {\n throw new ValidationError('Amount must be greater than 0', 'amount');\n }\n\n if (partnerFee !== undefined) {\n const partnerFeeAmount = this.toMoney(partnerFee, uppercaseCurrency, 'partnerFee');\n\n if (partnerFeeAmount.isNegative()) {\n throw new ValidationError('partnerFee cannot be negative', 'partnerFee');\n }\n\n if (partnerFeeAmount.greaterThan(paymentAmount)) {\n throw new ValidationError('partnerFee cannot exceed the payment amount', 'partnerFee');\n }\n }\n }\n\n private toMoney(value: number, currency: string, fieldName: string): Money {\n try {\n return Money.fromInteger(value, currency);\n } catch {\n throw new ValidationError(\n `${fieldName} must be an integer in the smallest currency unit (e.g., cents for USD)`,\n fieldName\n );\n }\n }\n\n private handlePaymentError(error: any): Error {\n if (error instanceof VerapayError) {\n return error;\n }\n return new PaymentError(error.message || 'Payment failed', error.code);\n }\n}\n","import type { CardValidation } from '../types';\n\nexport class CardValidator {\n validateCardNumber(cardNumber: string): boolean {\n const cleaned = cardNumber.replace(/\\D/g, '');\n\n if (cleaned.length < 13 || cleaned.length > 19) {\n return false;\n }\n\n let sum = 0;\n let isEven = false;\n\n for (let i = cleaned.length - 1; i >= 0; i--) {\n let digit = parseInt(cleaned[i], 10);\n\n if (isEven) {\n digit *= 2;\n if (digit > 9) {\n digit -= 9;\n }\n }\n\n sum += digit;\n isEven = !isEven;\n }\n\n return sum % 10 === 0;\n }\n\n detectCardType(cardNumber: string): string {\n const cleaned = cardNumber.replace(/\\D/g, '');\n\n if (/^4/.test(cleaned)) return 'visa';\n if (/^5[1-5]/.test(cleaned)) return 'mastercard';\n if (/^3[47]/.test(cleaned)) return 'amex';\n if (/^6(?:011|5)/.test(cleaned)) return 'discover';\n\n return 'unknown';\n }\n\n validateExpiry(month: number, year: number): boolean {\n const now = new Date();\n const currentYear = now.getFullYear();\n const currentMonth = now.getMonth() + 1;\n\n if (month < 1 || month > 12) {\n return false;\n }\n\n const fullYear = year < 100 ? 2000 + year : year;\n\n if (fullYear < currentYear) {\n return false;\n }\n\n if (fullYear === currentYear && month < currentMonth) {\n return false;\n }\n\n return true;\n }\n\n validateCVC(cvc: string, cardType: string = 'unknown'): boolean {\n const cleaned = cvc.replace(/\\D/g, '');\n\n if (cardType === 'amex') {\n return cleaned.length === 4;\n }\n\n return cleaned.length === 3 || cleaned.length === 4;\n }\n\n validateAll(\n cardNumber: string,\n expiryMonth: number,\n expiryYear: number,\n cvc: string\n ): CardValidation {\n const cardType = this.detectCardType(cardNumber);\n\n return {\n number: {\n isValid: this.validateCardNumber(cardNumber),\n cardType: cardType as any,\n },\n expiry: {\n isValid: this.validateExpiry(expiryMonth, expiryYear),\n month: expiryMonth,\n year: expiryYear,\n },\n cvc: {\n isValid: this.validateCVC(cvc, cardType),\n length: cvc.replace(/\\D/g, '').length,\n },\n };\n }\n}\n","export class InputSanitizer {\n static sanitizeCardNumber(input: string): string {\n return input.replace(/\\D/g, '');\n }\n\n static formatCardNumber(input: string): string {\n const cleaned = this.sanitizeCardNumber(input);\n return cleaned.replace(/(\\d{4})/g, '$1 ').trim();\n }\n\n static sanitizeCVC(input: string): string {\n return input.replace(/\\D/g, '').slice(0, 4);\n }\n\n static sanitizeExpiry(input: string): { month: number; year: number } | null {\n const cleaned = input.replace(/\\D/g, '');\n\n if (cleaned.length === 4) {\n return {\n month: parseInt(cleaned.slice(0, 2), 10),\n year: parseInt(cleaned.slice(2, 4), 10),\n };\n } else if (cleaned.length === 6) {\n return {\n month: parseInt(cleaned.slice(0, 2), 10),\n year: parseInt(cleaned.slice(2, 6), 10),\n };\n }\n\n return null;\n }\n}\n","export { VerapayClient } from './client/verapay-client';\nexport { VerapayService } from './services/verapay-service';\n\nexport type {\n InitialisePaymentRequest,\n InitialisePaymentResponse,\n ProcessPrePaymentRequest,\n} from './services/verapay-service';\n\nexport type {\n VerapayConfig,\n ElementsConfig,\n ProcessPaymentRequest,\n PaymentResult,\n CardValidation,\n ErrorDetails,\n ErrorCode,\n} from './types';\n\nexport {\n VerapayError,\n ValidationError,\n PaymentError,\n ErrorFormatter,\n} from './errors';\n\nexport { CardValidator, InputSanitizer } from './validation';\n\nexport type {\n PaymentExtension,\n DatabaseExtension,\n AnalyticsExtension,\n} from './extensions';\n\nexport const VERSION = '0.0.1';\n"]}
1
+ {"version":3,"sources":["../src/errors/verapay-error.ts","../src/errors/validation-error.ts","../src/errors/payment-error.ts","../src/errors/error-formatter.ts","../src/client/stripe-adapter.ts","../src/client/elements-manager.ts","../src/client/payment-extensions-manager.ts","../src/services/payment-service.ts","../src/services/verapay-service.ts","../src/client/verapay-client.ts","../src/validation/card-validator.ts","../src/validation/input-sanitizer.ts","../src/index.ts"],"names":["VerapayError","_VerapayError","message","code","details","ValidationError","field","metadata","PaymentError","_PaymentError","stripeCode","ErrorFormatter","error","StripeAdapter","stripe","paymentMethodId","clientSecret","result","elements","isUsingIndividualFormElements","address","DEFAULT_CARD_ELEMENT_CONFIG","FIELD_LABELS","ElementsManager","config","selector","elementsConfig","element","mode","fieldType","options","formFieldType","errors","state","handleElementChange","event","PaymentExtensionsManager","extension","request","modifiedRequest","ext","PaymentService","stripeAdapter","elementsManager","verapayService","context","validation","isUsingStripePaymentElement","VerapayService","baseUrl","apiKey","merchantId","paymentData","response","errorData","data","status","record","candidates","candidate","_VerapayClient","backendUrl","paymentIntentId","stripePublishableKey","loadStripe","paymentResult","amount","currency","partnerFee","uppercaseCurrency","paymentAmount","partnerFeeAmount","value","fieldName","Money","VerapayClient","CardValidator","cardNumber","cleaned","sum","isEven","i","digit","month","year","now","currentYear","currentMonth","fullYear","cvc","cardType","expiryMonth","expiryYear","InputSanitizer","input","VERSION"],"mappings":"wEAGO,IAAMA,CAAAA,CAAN,MAAMC,CAAAA,SAAqB,KAAM,CAItC,YACEC,CAAAA,CACAC,CAAAA,CAAAA,gBAAAA,CACAC,CAAAA,CACA,CACA,KAAA,CAAMF,CAAO,CAAA,CACb,IAAA,CAAK,KAAO,cAAA,CACZ,IAAA,CAAK,IAAA,CAAOC,CAAAA,CACZ,IAAA,CAAK,OAAA,CAAU,CACb,IAAA,CAAAA,EACA,OAAA,CAAAD,CAAAA,CACA,gBAAA,CAAkB,IAAA,CAAK,aAAA,CAAcA,CAAAA,CAASC,CAAI,CAAA,CAClD,GAAGC,C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CAAG,EAAE,CACxC,CAAA,CACSA,CAAAA,CAAQ,MAAA,GAAW,CAAA,CACrB,CACL,KAAA,CAAO,QAAA,CAASA,CAAAA,CAAQ,MAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,CAAA,CACvC,IAAA,CAAM,QAAA,CAASA,CAAAA,CAAQ,MAAM,CAAA,CAAG,CAAC,CAAA,CAAG,EAAE,CACxC,CAAA,CAGK,IACT,CACF,MCGaiB,EAAAA,CAAU","file":"index.js","sourcesContent":["import type { ErrorDetails } from '../types';\nimport { ErrorCode } from '../types';\n\nexport class VerapayError extends Error {\n public readonly code: ErrorCode;\n public readonly details: ErrorDetails;\n\n constructor(\n message: string,\n code: ErrorCode = ErrorCode.PAYMENT_FAILED,\n details?: Partial<ErrorDetails>\n ) {\n super(message);\n this.name = 'VerapayError';\n this.code = code;\n this.details = {\n code,\n message,\n formattedMessage: this.formatMessage(message, code),\n ...details,\n };\n\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, VerapayError);\n }\n }\n\n private formatMessage(message: string, code: ErrorCode): string {\n const messageMap: Record<ErrorCode, string> = {\n [ErrorCode.VALIDATION_ERROR]:\n 'Please check your payment information and try again.',\n [ErrorCode.PAYMENT_FAILED]:\n 'Your payment could not be processed. Please try again.',\n [ErrorCode.AUTHENTICATION_FAILED]:\n 'Payment authentication failed. Please try again.',\n [ErrorCode.NETWORK_ERROR]:\n 'Network error. Please check your connection and try again.',\n [ErrorCode.STRIPE_ERROR]:\n 'Payment service error. Please try again later.',\n [ErrorCode.CONFIGURATION_ERROR]:\n 'Configuration error. Please contact support.',\n [ErrorCode.CARD_DECLINED]:\n 'Your card was declined. Please use a different payment method.',\n [ErrorCode.INSUFFICIENT_FUNDS]:\n 'Insufficient funds. Please use a different payment method.',\n [ErrorCode.EXPIRED_CARD]:\n 'Your card has expired. Please use a different payment method.',\n };\n\n return messageMap[code] || message;\n }\n\n toJSON() {\n return {\n name: this.name,\n code: this.code,\n message: this.message,\n details: this.details,\n };\n }\n}\n","import { VerapayError } from './verapay-error';\nimport { ErrorCode } from '../types';\n\nexport class ValidationError extends VerapayError {\n constructor(message: string, field?: string, metadata?: Record<string, any>) {\n super(message, ErrorCode.VALIDATION_ERROR, {\n field,\n metadata,\n });\n this.name = 'ValidationError';\n }\n}\n","import { VerapayError } from './verapay-error';\nimport { ErrorCode } from '../types';\n\nexport class PaymentError extends VerapayError {\n constructor(\n message: string,\n stripeCode?: string,\n metadata?: Record<string, any>\n ) {\n const code = PaymentError.mapStripeCode(stripeCode);\n super(message, code, {\n stripeCode,\n metadata,\n });\n this.name = 'PaymentError';\n }\n\n private static mapStripeCode(stripeCode?: string): ErrorCode {\n if (!stripeCode) return ErrorCode.PAYMENT_FAILED;\n\n const codeMap: Record<string, ErrorCode> = {\n card_declined: ErrorCode.CARD_DECLINED,\n insufficient_funds: ErrorCode.INSUFFICIENT_FUNDS,\n expired_card: ErrorCode.EXPIRED_CARD,\n incorrect_cvc: ErrorCode.VALIDATION_ERROR,\n processing_error: ErrorCode.PAYMENT_FAILED,\n authentication_failed: ErrorCode.AUTHENTICATION_FAILED,\n };\n\n return codeMap[stripeCode] || ErrorCode.PAYMENT_FAILED;\n }\n}\n","import type { ErrorDetails } from '../types';\n\nexport class ErrorFormatter {\n static formatForUser(error: Error | ErrorDetails): string {\n if ('formattedMessage' in error) {\n return error.formattedMessage;\n }\n if (\n 'details' in error &&\n error.details &&\n typeof error.details === 'object' &&\n 'formattedMessage' in error.details &&\n typeof error.details.formattedMessage === 'string'\n ) {\n return error.details.formattedMessage;\n }\n return 'An unexpected error occurred. Please try again.';\n }\n\n static formatForDeveloper(error: Error | ErrorDetails): string {\n if ('code' in error && 'message' in error) {\n return `[${error.code}] ${error.message}`;\n }\n return error.message || 'Unknown error';\n }\n\n static toJSON(error: Error | ErrorDetails): Record<string, any> {\n if ('toJSON' in error && typeof error.toJSON === 'function') {\n return error.toJSON();\n }\n\n return {\n name: (error as Error).name || 'Error',\n message: error.message,\n ...('code' in error && { code: error.code }),\n ...('details' in error && { details: error.details }),\n };\n }\n}\n","import type { PaymentIntent, Stripe, StripeElements } from '@stripe/stripe-js';\nimport { PaymentError } from '../errors';\n\nexport class StripeAdapter {\n constructor(private stripe: Stripe) {}\n\n async confirmPayment(\n paymentMethodId: string,\n clientSecret: string\n ): Promise<{ paymentIntent: PaymentIntent }> {\n const result = await this.stripe.confirmPayment({\n clientSecret,\n confirmParams: {\n payment_method: paymentMethodId,\n return_url: window.location.href,\n },\n redirect: 'if_required',\n });\n\n if (result.error) {\n throw new PaymentError(\n result.error.message || 'Payment failed',\n result.error.code\n );\n }\n\n return result as { paymentIntent: PaymentIntent };\n }\n\n async confirmCardPayment(\n paymentMethodId: string,\n clientSecret: string\n ): Promise<{ paymentIntent: PaymentIntent }> {\n const result = await this.stripe.confirmCardPayment(clientSecret, {\n payment_method: paymentMethodId,\n });\n\n if (result.error) {\n throw new PaymentError(\n result.error.message || 'Payment failed',\n result.error.code\n );\n }\n\n return result as { paymentIntent: PaymentIntent };\n }\n\n async createPaymentMethod(\n elements: StripeElements,\n isUsingIndividualFormElements: boolean = false\n ): Promise<string> {\n let result;\n\n if (!isUsingIndividualFormElements) {\n result = await this.stripe.createPaymentMethod({\n elements,\n });\n } else {\n // @ts-ignore - Stripe types don't include mode parameter for getElement\n const addressElement = await elements.getElement('address', { mode: 'billing' })!.getValue();\n const address = addressElement!.value;\n\n result = await this.stripe.createPaymentMethod({\n type: 'card',\n card: elements.getElement('cardNumber')!,\n billing_details: {\n name: address.name,\n address: {\n ...address.address,\n line2: address.address.line2 ?? undefined,\n },\n },\n });\n }\n\n if (result.error || !result.paymentMethod) {\n throw new PaymentError(\n result.error?.message || 'Failed to create payment method',\n result.error?.code\n );\n }\n\n return result.paymentMethod.id;\n }\n}\n","import type {\n Stripe,\n StripeElements,\n StripeElement,\n StripePaymentElement,\n StripeCardNumberElement,\n PaymentWalletsOption,\n} from '@stripe/stripe-js';\nimport type { VerapayConfig, ValidationError, ValidationResult } from '../types';\nimport { VerapayError, ErrorCode } from '../errors';\n\ntype ElementState = { complete: boolean; error?: string }\n\nconst DEFAULT_CARD_ELEMENT_CONFIG = {\n showIcon: true,\n iconStyle: 'solid' as const,\n placeholders: {\n cardNumber: '1234 1234 1234 1234',\n cardExpiry: 'MM / YY - TESTING',\n cardCvc: 'CVC',\n },\n style: {\n base: {\n color: '#333333',\n fontFamily: 'system-ui, -apple-system, sans-serif',\n fontSize: '16px',\n '::placeholder': { color: '#aab7c4' },\n },\n complete: {\n color: '#333333',\n },\n empty: {},\n invalid: {\n color: '#df1b41',\n },\n },\n}\n\nconst FIELD_LABELS: Record<string, string> = {\n cardNumber: 'Card number',\n cardExpiry: 'Expiry date',\n cardCvc: 'CVC',\n address: 'Address',\n}\n\nexport class ElementsManager {\n private elements: StripeElements | null = null;\n private mountedElements: Map<string, StripeElement> = new Map();\n private elementStates: Map<string, ElementState> = new Map();\n\n constructor(\n private stripe: Stripe,\n private config: VerapayConfig,\n private clientSecret: string\n ) {\n if (!clientSecret) {\n throw new VerapayError(\n 'Client secret not initialized',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n mountPaymentElement(selector: string): void {\n if (!this.elements) {\n const elementsConfig = {\n clientSecret: this.clientSecret,\n appearance: this.config.appearance,\n locale: this.config.locale,\n fonts: this.config.fonts,\n paymentMethodCreation: 'manual',\n };\n\n this.elements = this.stripe.elements(elementsConfig);\n }\n\n const container = document.querySelector(selector);\n\n if (!container) {\n throw new VerapayError(\n `Element not found: ${selector}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const element = this.elements.create('payment', {\n layout: 'tabs',\n wallets: { link: 'never' } as unknown as PaymentWalletsOption,\n }) as StripePaymentElement;\n\n element.mount(selector);\n this.mountedElements.set('payment', element);\n }\n\n mountCardNumberElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardNumber', this.cardElementOptions('cardNumber'));\n }\n\n mountCardExpiryElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardExpiry', this.cardElementOptions('cardExpiry'));\n }\n\n mountCardCvcElement(selector: string): void {\n this.mountIndividualFormElement(selector, 'cardCvc', this.cardElementOptions('cardCvc'));\n }\n\n mountAddressElement(selector: string, mode: 'billing' | 'shipping'): void {\n this.mountIndividualFormElement(selector, 'address', { mode });\n }\n\n private cardElementOptions(fieldType: 'cardNumber' | 'cardExpiry' | 'cardCvc'): Record<string, unknown> {\n const { elementsConfig } = this.config;\n const options: Record<string, unknown> = {\n placeholder: elementsConfig?.placeholders?.[fieldType] ?? DEFAULT_CARD_ELEMENT_CONFIG.placeholders[fieldType],\n style: {\n base: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.base, ...elementsConfig?.style?.base },\n complete: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.complete, ...elementsConfig?.style?.complete },\n empty: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.empty, ...elementsConfig?.style?.empty },\n invalid: { ...DEFAULT_CARD_ELEMENT_CONFIG.style.invalid, ...elementsConfig?.style?.invalid },\n },\n };\n\n if (fieldType === 'cardNumber') {\n options.showIcon = elementsConfig?.showIcon ?? DEFAULT_CARD_ELEMENT_CONFIG.showIcon;\n options.iconStyle = elementsConfig?.iconStyle ?? DEFAULT_CARD_ELEMENT_CONFIG.iconStyle;\n }\n\n return options;\n }\n\n private mountIndividualFormElement(selector: string, formFieldType: 'cardNumber' | 'cardExpiry' | 'cardCvc' | 'address', options?: Record<string, unknown>) {\n const container = document.querySelector(selector);\n\n if (!container) {\n throw new VerapayError(\n `Element not found: ${selector}`,\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const element = this.createIndividualFormElement(formFieldType, options) as StripeCardNumberElement;\n element.mount(selector);\n\n this.mountedElements.set(formFieldType, element);\n this.trackElementState(formFieldType, element);\n }\n\n private createIndividualFormElement(\n formFieldType: any,\n options?: Record<string, unknown>\n ): StripeElement {\n if (!this.elements) {\n // For individual card elements, don't pass clientSecret\n // It's only needed when creating Payment Element or confirming payment\n this.elements = this.stripe.elements({\n appearance: this.config.appearance,\n locale: this.config.locale,\n fonts: this.config.fonts,\n paymentMethodCreation: 'manual',\n });\n }\n\n return this.elements.create(formFieldType, options);\n }\n\n async validate(): Promise<ValidationResult> {\n const errors: ValidationError[] = []\n\n for (const [field, state] of this.elementStates.entries()) {\n if (!state.complete) {\n errors.push({\n field,\n message: state.error ?? `${FIELD_LABELS[field] ?? field} failed validation`,\n })\n }\n }\n\n return { isValid: errors.length === 0, errors }\n }\n\n getElements(): StripeElements | null {\n return this.elements;\n }\n\n unmountAll(): void {\n for (const element of this.mountedElements.values()) {\n element.unmount();\n }\n this.mountedElements.clear();\n this.elementStates.clear();\n }\n\n private trackElementState(field: string, element: StripeElement): void {\n this.elementStates.set(field, { complete: false })\n\n const handleElementChange = (event: { complete: boolean; error?: { message: string } }) => {\n this.elementStates.set(field, { complete: event.complete, error: event.error?.message })\n };\n\n (element as any).on('change', handleElementChange)\n }\n}\n","import type { ProcessPaymentRequest, PaymentResult } from '../types'\nimport type { PaymentExtension } from '../extensions'\n\nexport class PaymentExtensionsManager {\n private extensions: PaymentExtension[] = []\n\n add(extension: PaymentExtension): void {\n this.extensions.push(extension)\n }\n\n async runBeforePayment(request: ProcessPaymentRequest): Promise<ProcessPaymentRequest> {\n let modifiedRequest = request\n for (const ext of this.extensions) {\n if (ext.beforePayment) {\n modifiedRequest = await ext.beforePayment(modifiedRequest)\n }\n }\n return modifiedRequest\n }\n\n async runAfterPayment(result: PaymentResult): Promise<void> {\n await Promise.all(\n this.extensions\n .filter((ext) => ext.afterPayment)\n .map((ext) => ext.afterPayment!(result)),\n )\n }\n\n async runOnError(error: Error): Promise<void> {\n await Promise.all(\n this.extensions\n .filter((ext) => ext.onPaymentError)\n .map((ext) => ext.onPaymentError!(error)),\n )\n }\n}\n","import { StripeAdapter } from '../client/stripe-adapter'\nimport { ElementsManager } from '../client/elements-manager'\nimport { ErrorCode, VerapayError } from '../errors'\nimport { VerapayService } from './verapay-service'\nimport type { ProcessPaymentRequest, PaymentResult } from '../types'\nimport { StripeElements } from '@stripe/stripe-js';\n\nexport interface ProcessPaymentContext {\n merchantId: string\n paymentIntentId: string\n clientSecret: string\n amount: number\n currency: string\n isUsingStripePaymentElement: boolean\n isUsingIndividualFormElements: boolean\n}\n\nexport class PaymentService {\n constructor(\n private stripeAdapter: StripeAdapter,\n private elementsManager: ElementsManager,\n private verapayService: VerapayService,\n ) {}\n\n async process(request: ProcessPaymentRequest, context: ProcessPaymentContext): Promise<PaymentResult> {\n const elements = this.elementsManager.getElements()\n\n await this.validatePaymentCanProceed(elements, context);\n\n await elements!.submit()\n\n const paymentMethodId = await this.stripeAdapter.createPaymentMethod(\n elements!,\n context.isUsingIndividualFormElements,\n )\n\n await this.verapayService.processPrePayment({\n merchantId: context.merchantId,\n paymentIntentId: context.paymentIntentId,\n paymentMethodId,\n amount: context.amount,\n currency: context.currency,\n customerData: {\n email: request.customerEmail,\n firstName: request.customerFirstName,\n lastName: request.customerLastName,\n },\n description: request.description,\n metadata: request.metadata,\n })\n\n return this.confirmPayment(paymentMethodId, context)\n }\n\n private async validatePaymentCanProceed(elements: StripeElements | null, context: ProcessPaymentContext) {\n if (!elements) {\n throw new VerapayError('Payment form not mounted', ErrorCode.CONFIGURATION_ERROR)\n }\n\n if (context.isUsingStripePaymentElement && context.isUsingIndividualFormElements) {\n throw new VerapayError('Both forms of payment form in use');\n }\n\n if (context.isUsingIndividualFormElements) {\n const validation = await this.elementsManager.validate()\n if (!validation.isValid) {\n throw new VerapayError(validation.errors[0].message, ErrorCode.VALIDATION_ERROR)\n }\n }\n }\n\n private async confirmPayment(\n paymentMethodId: string,\n context: ProcessPaymentContext,\n ): Promise<PaymentResult> {\n const { clientSecret, isUsingStripePaymentElement, isUsingIndividualFormElements } = context\n\n let result\n\n if (isUsingStripePaymentElement) {\n result = await this.stripeAdapter.confirmPayment(paymentMethodId, clientSecret)\n } else if (isUsingIndividualFormElements) {\n result = await this.stripeAdapter.confirmCardPayment(paymentMethodId, clientSecret)\n }\n\n return this.formatPaymentResult(result)\n }\n\n private formatPaymentResult(result: any): PaymentResult {\n return {\n success: result.paymentIntent.status === 'succeeded',\n paymentIntentId: result.paymentIntent.id,\n status: result.paymentIntent.status,\n }\n }\n}\n","import { ErrorCode, VerapayError } from '../errors';\nimport { PaymentData } from '../types';\n\nexport interface InitialisePaymentRequest {\n merchantId: string;\n paymentData: PaymentData;\n}\n\nexport interface InitialisePaymentResponse {\n paymentIntentId: string;\n clientSecret: string;\n connectAccountId: string;\n stripePublishableKey: string;\n}\n\nexport interface ProcessPrePaymentRequest {\n merchantId: string;\n paymentIntentId: string;\n paymentMethodId: string;\n amount: number;\n currency: string;\n customerData: Record<string, any>;\n description?: string;\n metadata?: Record<string, string>;\n}\n\nexport class VerapayService {\n private readonly baseUrl: string;\n private readonly apiKey: string;\n\n constructor(baseUrl: string, apiKey: string) {\n this.baseUrl = baseUrl;\n this.apiKey = apiKey;\n }\n\n async initialisePayment(\n request: InitialisePaymentRequest\n ): Promise<InitialisePaymentResponse> {\n const { merchantId, paymentData } = request;\n\n try {\n const response = await fetch(`${this.baseUrl}/api/initialise-payment`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': this.apiKey,\n },\n body: JSON.stringify({\n merchantId,\n paymentData: { ...paymentData, paymentMethodType: 'card' },\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n throw new VerapayError(\n this.extractErrorMessage(errorData, response.status),\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n const data = await response.json();\n\n if (!data.clientSecret || !data.paymentIntentId) {\n throw new VerapayError(\n 'Missing clientSecret or paymentIntentId in server response',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n return {\n paymentIntentId: data.paymentIntentId,\n clientSecret: data.clientSecret,\n connectAccountId: data.connectAccountId,\n stripePublishableKey: data.stripePublishableKey,\n };\n } catch (error) {\n if (error instanceof VerapayError) {\n throw error;\n }\n throw new VerapayError(\n error instanceof Error ? error.message : 'Unknown error occurred',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n async processPrePayment(request: ProcessPrePaymentRequest): Promise<void> {\n try {\n const response = await fetch(`${this.baseUrl}/api/process-prepayment`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'x-api-key': this.apiKey,\n },\n body: JSON.stringify({\n merchantId: request.merchantId,\n paymentIntentId: request.paymentIntentId,\n paymentMethodId: request.paymentMethodId,\n amount: request.amount,\n currency: request.currency,\n customerData: request.customerData,\n description: request.description,\n metadata: request.metadata,\n }),\n });\n\n if (!response.ok) {\n const errorData = await response.json().catch(() => ({}));\n throw new VerapayError(\n this.extractErrorMessage(errorData, response.status),\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n } catch (error) {\n if (error instanceof VerapayError) {\n throw error;\n }\n throw new VerapayError(\n error instanceof Error ? error.message : 'Unknown error occurred',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n }\n\n private extractErrorMessage(errorData: unknown, status: number): string {\n if (!errorData || typeof errorData !== 'object') {\n return `HTTP error! status: ${status}`;\n }\n\n const record = errorData as Record<string, unknown>;\n const candidates = [record.error, record.message, record.details];\n\n for (const candidate of candidates) {\n if (typeof candidate === 'string' && candidate.trim().length > 0) {\n return candidate;\n }\n\n if (candidate && typeof candidate === 'object') {\n try {\n return JSON.stringify(candidate);\n } catch {\n // Ignore serialization issues and continue trying fallback messages.\n }\n }\n }\n\n return `HTTP error! status: ${status}`;\n }\n}\n","import { loadStripe } from '@stripe/stripe-js';\nimport { Money } from 'ts-money';\nimport { StripeAdapter } from './stripe-adapter';\nimport { ElementsManager } from './elements-manager';\nimport type { PaymentExtension } from '../extensions';\nimport { PaymentExtensionsManager } from './payment-extensions-manager';\nimport { PaymentService } from '../services/payment-service';\nimport {\n ErrorCode,\n VerapayError,\n PaymentError,\n ValidationError,\n} from '../errors';\nimport { VerapayService } from '../services/verapay-service';\nimport type {\n VerapayConfig,\n ProcessPaymentRequest,\n PaymentResult,\n} from '../types';\n\nexport class VerapayClient {\n private static readonly BACKEND_URL = 'https://api.verapay.app';\n private static readonly BACKEND_URL_TEST_MODE = 'https://test-api.verapay.app';\n\n private config: VerapayConfig;\n private verapayService: VerapayService;\n private extensionsManager: PaymentExtensionsManager;\n\n private stripeAdapter: StripeAdapter | null = null;\n private elementsManager: ElementsManager | null = null;\n private paymentService: PaymentService | null = null;\n\n private isUsingStripePaymentElement: boolean = false;\n private isUsingIndividualFormElements: boolean = false;\n\n private clientSecret: string | null = null;\n private paymentIntentId: string | null = null;\n\n constructor(config: VerapayConfig) {\n if (!config.apiKey) {\n throw new VerapayError(\n 'apiKey is required. Pass your Verapay publishable key (vpy_pk_test_... or vpy_pk_live_...) when constructing VerapayClient.',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n this.config = config;\n\n if (!this.config.apiKey.includes(\"_pk_\") && typeof window !== \"undefined\") {\n console.warn(\n \"Verapay Security Warning: You are using a Secret Key in a frontend environment. Please use a Publishable Key (vpy_pk_...) instead.\"\n );\n }\n\n const backendUrl =\n this.config.apiUrlOverride ||\n (this.isTestKey()\n ? VerapayClient.BACKEND_URL_TEST_MODE\n : VerapayClient.BACKEND_URL);\n\n this.verapayService = new VerapayService(backendUrl, this.config.apiKey);\n this.extensionsManager = new PaymentExtensionsManager();\n }\n\n async initialize(): Promise<void> {\n this.validatePaymentInitialisation()\n\n const { clientSecret, paymentIntentId, stripePublishableKey } =\n await this.verapayService.initialisePayment({\n merchantId: this.config.merchantId ?? '',\n paymentData: this.config.paymentData\n });\n\n this.clientSecret = clientSecret;\n this.paymentIntentId = paymentIntentId;\n\n const stripe = await loadStripe(stripePublishableKey);\n\n if (!stripe) {\n throw new VerapayError(\n 'Failed to load Stripe',\n ErrorCode.CONFIGURATION_ERROR\n );\n }\n\n this.stripeAdapter = new StripeAdapter(stripe);\n this.elementsManager = new ElementsManager(\n stripe,\n this.config,\n clientSecret\n );\n this.paymentService = new PaymentService(\n this.stripeAdapter,\n this.elementsManager,\n this.verapayService\n );\n }\n\n async processPayment(request: ProcessPaymentRequest): Promise<PaymentResult> {\n await this.ensureInitialized();\n\n let modifiedRequest =\n await this.extensionsManager.runBeforePayment(request);\n\n try {\n const paymentResult = await this.paymentService!.process(\n modifiedRequest,\n {\n merchantId: this.config.merchantId ?? '',\n paymentIntentId: this.paymentIntentId!,\n clientSecret: this.clientSecret!,\n amount: this.config.paymentData.amount,\n currency: this.config.paymentData.currency,\n isUsingStripePaymentElement: this.isUsingStripePaymentElement,\n isUsingIndividualFormElements: this.isUsingIndividualFormElements,\n }\n );\n\n await this.extensionsManager.runAfterPayment(paymentResult);\n\n return paymentResult;\n } catch (error) {\n await this.extensionsManager.runOnError(error as Error);\n throw this.handlePaymentError(error);\n }\n }\n\n async mountPaymentForm(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountPaymentElement(selector);\n this.isUsingStripePaymentElement = true;\n }\n\n async mountCardNumber(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardNumberElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountCardExpiry(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardExpiryElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountCardCvc(selector: string): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountCardCvcElement(selector);\n this.isUsingIndividualFormElements = true;\n }\n\n async mountAddress(\n selector: string,\n mode: 'billing' | 'shipping'\n ): Promise<void> {\n await this.ensureInitialized();\n this.elementsManager!.mountAddressElement(selector, mode);\n this.isUsingIndividualFormElements = true;\n }\n\n addExtension(extension: PaymentExtension): void {\n this.extensionsManager.add(extension);\n }\n\n private async ensureInitialized(): Promise<void> {\n if (!this.stripeAdapter) {\n await this.initialize();\n }\n }\n\n private validatePaymentInitialisation(): void {\n const { amount, currency, partnerFee } = this.config.paymentData;\n\n if (!currency) {\n throw new ValidationError('Currency is required', 'currency');\n }\n\n const uppercaseCurrency = currency.toUpperCase();\n\n const paymentAmount = this.toMoney(amount, uppercaseCurrency, 'amount');\n\n if (paymentAmount.isZero() || paymentAmount.isNegative()) {\n throw new ValidationError('Amount must be greater than 0', 'amount');\n }\n\n if (partnerFee !== undefined) {\n const partnerFeeAmount = this.toMoney(partnerFee, uppercaseCurrency, 'partnerFee');\n\n if (partnerFeeAmount.isNegative()) {\n throw new ValidationError('partnerFee cannot be negative', 'partnerFee');\n }\n\n if (partnerFeeAmount.greaterThan(paymentAmount)) {\n throw new ValidationError('partnerFee cannot exceed the payment amount', 'partnerFee');\n }\n }\n }\n\n private toMoney(value: number, currency: string, fieldName: string): Money {\n try {\n return Money.fromInteger(value, currency);\n } catch {\n throw new ValidationError(\n `${fieldName} must be an integer in the smallest currency unit (e.g., cents for USD)`,\n fieldName\n );\n }\n }\n\n private isTestKey(): boolean {\n return (\n this.config.apiKey.startsWith('vpy_pk_test_') ||\n this.config.apiKey.startsWith('vpy_test_')\n );\n }\n\n private handlePaymentError(error: any): Error {\n if (error instanceof VerapayError) {\n return error;\n }\n return new PaymentError(error.message || 'Payment failed', error.code);\n }\n}\n","import type { CardValidation } from '../types';\n\nexport class CardValidator {\n validateCardNumber(cardNumber: string): boolean {\n const cleaned = cardNumber.replace(/\\D/g, '');\n\n if (cleaned.length < 13 || cleaned.length > 19) {\n return false;\n }\n\n let sum = 0;\n let isEven = false;\n\n for (let i = cleaned.length - 1; i >= 0; i--) {\n let digit = parseInt(cleaned[i], 10);\n\n if (isEven) {\n digit *= 2;\n if (digit > 9) {\n digit -= 9;\n }\n }\n\n sum += digit;\n isEven = !isEven;\n }\n\n return sum % 10 === 0;\n }\n\n detectCardType(cardNumber: string): string {\n const cleaned = cardNumber.replace(/\\D/g, '');\n\n if (/^4/.test(cleaned)) return 'visa';\n if (/^5[1-5]/.test(cleaned)) return 'mastercard';\n if (/^3[47]/.test(cleaned)) return 'amex';\n if (/^6(?:011|5)/.test(cleaned)) return 'discover';\n\n return 'unknown';\n }\n\n validateExpiry(month: number, year: number): boolean {\n const now = new Date();\n const currentYear = now.getFullYear();\n const currentMonth = now.getMonth() + 1;\n\n if (month < 1 || month > 12) {\n return false;\n }\n\n const fullYear = year < 100 ? 2000 + year : year;\n\n if (fullYear < currentYear) {\n return false;\n }\n\n if (fullYear === currentYear && month < currentMonth) {\n return false;\n }\n\n return true;\n }\n\n validateCVC(cvc: string, cardType: string = 'unknown'): boolean {\n const cleaned = cvc.replace(/\\D/g, '');\n\n if (cardType === 'amex') {\n return cleaned.length === 4;\n }\n\n return cleaned.length === 3 || cleaned.length === 4;\n }\n\n validateAll(\n cardNumber: string,\n expiryMonth: number,\n expiryYear: number,\n cvc: string\n ): CardValidation {\n const cardType = this.detectCardType(cardNumber);\n\n return {\n number: {\n isValid: this.validateCardNumber(cardNumber),\n cardType: cardType as any,\n },\n expiry: {\n isValid: this.validateExpiry(expiryMonth, expiryYear),\n month: expiryMonth,\n year: expiryYear,\n },\n cvc: {\n isValid: this.validateCVC(cvc, cardType),\n length: cvc.replace(/\\D/g, '').length,\n },\n };\n }\n}\n","export class InputSanitizer {\n static sanitizeCardNumber(input: string): string {\n return input.replace(/\\D/g, '');\n }\n\n static formatCardNumber(input: string): string {\n const cleaned = this.sanitizeCardNumber(input);\n return cleaned.replace(/(\\d{4})/g, '$1 ').trim();\n }\n\n static sanitizeCVC(input: string): string {\n return input.replace(/\\D/g, '').slice(0, 4);\n }\n\n static sanitizeExpiry(input: string): { month: number; year: number } | null {\n const cleaned = input.replace(/\\D/g, '');\n\n if (cleaned.length === 4) {\n return {\n month: parseInt(cleaned.slice(0, 2), 10),\n year: parseInt(cleaned.slice(2, 4), 10),\n };\n } else if (cleaned.length === 6) {\n return {\n month: parseInt(cleaned.slice(0, 2), 10),\n year: parseInt(cleaned.slice(2, 6), 10),\n };\n }\n\n return null;\n }\n}\n","export { VerapayClient } from './client/verapay-client';\nexport { VerapayService } from './services/verapay-service';\n\nexport type {\n InitialisePaymentRequest,\n InitialisePaymentResponse,\n ProcessPrePaymentRequest,\n} from './services/verapay-service';\n\nexport type {\n VerapayConfig,\n ElementsConfig,\n ProcessPaymentRequest,\n PaymentResult,\n CardValidation,\n ErrorDetails,\n ErrorCode,\n} from './types';\n\nexport {\n VerapayError,\n ValidationError,\n PaymentError,\n ErrorFormatter,\n} from './errors';\n\nexport { CardValidator, InputSanitizer } from './validation';\n\nexport type {\n PaymentExtension,\n DatabaseExtension,\n AnalyticsExtension,\n} from './extensions';\n\nexport const VERSION = '1.1.0';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verapay/verapay-js",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "Simple TypeScript SDK for Stripe payment processing",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -8,9 +8,9 @@
8
8
  "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
+ "types": "./dist/index.d.ts",
11
12
  "import": "./dist/index.js",
12
- "require": "./dist/index.cjs",
13
- "types": "./dist/index.d.ts"
13
+ "require": "./dist/index.cjs"
14
14
  }
15
15
  },
16
16
  "files": [