@benbraide/inlinejs-stripe 1.0.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/inlinejs-stripe.js +3127 -1149
- package/dist/inlinejs-stripe.min.js +1 -1
- package/lib/common/components/detail.d.ts +14 -0
- package/lib/common/components/detail.js +60 -0
- package/lib/common/components/field.d.ts +23 -0
- package/lib/common/components/field.js +135 -0
- package/lib/common/components/payment-method.d.ts +12 -0
- package/lib/common/components/payment-method.js +35 -0
- package/lib/common/components/stripe.d.ts +28 -0
- package/lib/common/components/stripe.js +139 -0
- package/lib/common/entry.d.ts +1 -0
- package/lib/common/entry.js +17 -0
- package/lib/common/index.d.ts +5 -1
- package/lib/common/index.js +5 -1
- package/lib/common/types.d.ts +20 -0
- package/lib/common/types.js +2 -0
- package/lib/esm/components/detail.d.ts +14 -0
- package/lib/esm/components/detail.js +55 -0
- package/lib/esm/components/field.d.ts +23 -0
- package/lib/esm/components/field.js +130 -0
- package/lib/esm/components/payment-method.d.ts +12 -0
- package/lib/esm/components/payment-method.js +30 -0
- package/lib/esm/components/stripe.d.ts +28 -0
- package/lib/esm/components/stripe.js +134 -0
- package/lib/esm/entry.d.ts +1 -0
- package/lib/esm/entry.js +13 -0
- package/lib/esm/index.d.ts +5 -1
- package/lib/esm/index.js +5 -1
- package/lib/esm/types.d.ts +20 -0
- package/lib/esm/types.js +1 -0
- package/package.json +5 -3
- package/src/inlinejs-stripe.ts +2 -4
@@ -0,0 +1,30 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
import { CustomElement, Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
|
8
|
+
export class StripePaymentMenthodElement extends CustomElement {
|
9
|
+
constructor() {
|
10
|
+
super({
|
11
|
+
isTemplate: true,
|
12
|
+
isHidden: true,
|
13
|
+
});
|
14
|
+
this.value = '';
|
15
|
+
}
|
16
|
+
WaitReady() {
|
17
|
+
return Promise.resolve();
|
18
|
+
}
|
19
|
+
ToggleFocus(focused) { }
|
20
|
+
Reset() { }
|
21
|
+
AddDetails(details) {
|
22
|
+
this.value && (details.method = this.value);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
__decorate([
|
26
|
+
Property({ type: 'object', checkStoredObject: true })
|
27
|
+
], StripePaymentMenthodElement.prototype, "value", void 0);
|
28
|
+
export function StripePaymentMenthodElementCompact() {
|
29
|
+
RegisterCustomElement(StripePaymentMenthodElement, 'stripe-payment-method');
|
30
|
+
}
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/// <reference types="stripe-v3" />
|
2
|
+
import { IElementScopeCreatedCallbackParams } from "@benbraide/inlinejs";
|
3
|
+
import { CustomElement } from "@benbraide/inlinejs-element";
|
4
|
+
import { IStripeElement, IStripeField } from "../types";
|
5
|
+
export declare class StripeElement extends CustomElement implements IStripeElement {
|
6
|
+
protected stripe_: stripe.Stripe | null;
|
7
|
+
protected mounting_: boolean;
|
8
|
+
protected mounted_: boolean;
|
9
|
+
protected fields_: Array<IStripeField> | null;
|
10
|
+
protected instanceWaiters_: (() => void)[];
|
11
|
+
options: stripe.elements.ElementsOptions | null;
|
12
|
+
publicKey: string;
|
13
|
+
onready: string;
|
14
|
+
defer: boolean;
|
15
|
+
autofocus: boolean;
|
16
|
+
constructor();
|
17
|
+
AddStripeField(field: IStripeField): void;
|
18
|
+
RemoveStripeField(field: IStripeField): void;
|
19
|
+
FocusNextField(field: IStripeField): void;
|
20
|
+
GetInstance(): stripe.Stripe | null;
|
21
|
+
WaitInstance(): Promise<stripe.Stripe | null>;
|
22
|
+
Mount(): void;
|
23
|
+
Pay(clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
|
24
|
+
Setup(clientSecret: string): Promise<false | stripe.PaymentIntentResponse>;
|
25
|
+
protected HandleElementScopeCreated_({ scope, ...rest }: IElementScopeCreatedCallbackParams, postAttributesCallback?: () => void): void;
|
26
|
+
protected PayOrSetup_(pay: boolean, clientSecret: string, save?: boolean): Promise<false | stripe.PaymentIntentResponse>;
|
27
|
+
}
|
28
|
+
export declare function StripeElementCompact(): void;
|
@@ -0,0 +1,134 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
8
|
+
var t = {};
|
9
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
10
|
+
t[p] = s[p];
|
11
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
12
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
13
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
14
|
+
t[p[i]] = s[p[i]];
|
15
|
+
}
|
16
|
+
return t;
|
17
|
+
};
|
18
|
+
import { JournalTry } from "@benbraide/inlinejs";
|
19
|
+
import { CustomElement, Property, RegisterCustomElement } from "@benbraide/inlinejs-element";
|
20
|
+
export class StripeElement extends CustomElement {
|
21
|
+
constructor() {
|
22
|
+
super();
|
23
|
+
this.stripe_ = null;
|
24
|
+
this.mounting_ = false;
|
25
|
+
this.mounted_ = false;
|
26
|
+
this.fields_ = null;
|
27
|
+
this.instanceWaiters_ = new Array();
|
28
|
+
this.options = null;
|
29
|
+
this.publicKey = '';
|
30
|
+
this.onready = '';
|
31
|
+
this.defer = false;
|
32
|
+
this.autofocus = false;
|
33
|
+
}
|
34
|
+
AddStripeField(field) {
|
35
|
+
this.fields_ = (this.fields_ || []);
|
36
|
+
this.fields_.push(field);
|
37
|
+
}
|
38
|
+
RemoveStripeField(field) {
|
39
|
+
this.fields_ && (this.fields_ = this.fields_.filter(x => x !== field));
|
40
|
+
}
|
41
|
+
FocusNextField(field) {
|
42
|
+
if (this.autofocus && this.fields_) {
|
43
|
+
const index = this.fields_.indexOf(field);
|
44
|
+
(index >= 0 && index < this.fields_.length - 1) && this.fields_[index + 1].ToggleFocus(true);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
GetInstance() {
|
48
|
+
return this.stripe_;
|
49
|
+
}
|
50
|
+
WaitInstance() {
|
51
|
+
return new Promise(resolve => {
|
52
|
+
this.mounted_ ? resolve(this.stripe_) : this.instanceWaiters_.push(() => resolve(this.stripe_));
|
53
|
+
});
|
54
|
+
}
|
55
|
+
Mount() {
|
56
|
+
if (this.mounted_ || this.mounting_) {
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
this.mounting_ = true;
|
60
|
+
this.LoadResources().then(() => {
|
61
|
+
this.mounting_ = false;
|
62
|
+
this.mounted_ = true;
|
63
|
+
this.stripe_ = Stripe(this.publicKey);
|
64
|
+
this.instanceWaiters_.splice(0).forEach(waiter => JournalTry(waiter));
|
65
|
+
});
|
66
|
+
}
|
67
|
+
Pay(clientSecret, save = false) {
|
68
|
+
return this.PayOrSetup_(true, clientSecret, save);
|
69
|
+
}
|
70
|
+
Setup(clientSecret) {
|
71
|
+
return this.PayOrSetup_(false, clientSecret);
|
72
|
+
}
|
73
|
+
HandleElementScopeCreated_(_a, postAttributesCallback) {
|
74
|
+
var { scope } = _a, rest = __rest(_a, ["scope"]);
|
75
|
+
super.HandleElementScopeCreated_(Object.assign({ scope }, rest), postAttributesCallback);
|
76
|
+
scope.AddPostProcessCallback(() => (!this.defer && this.Mount()));
|
77
|
+
scope.AddUninitCallback(() => (this.stripe_ = null));
|
78
|
+
}
|
79
|
+
PayOrSetup_(pay, clientSecret, save = false) {
|
80
|
+
return new Promise((resolve, reject) => {
|
81
|
+
this.WaitInstance().then((stripe) => {
|
82
|
+
var _a, _b;
|
83
|
+
if (!stripe) {
|
84
|
+
return resolve(false);
|
85
|
+
}
|
86
|
+
const details = {};
|
87
|
+
(_a = this.fields_) === null || _a === void 0 ? void 0 : _a.forEach(field => field.AddDetails(details));
|
88
|
+
if (!details.method) {
|
89
|
+
return resolve(false);
|
90
|
+
}
|
91
|
+
let cardDetails;
|
92
|
+
if (typeof details.method !== 'string') {
|
93
|
+
cardDetails = {
|
94
|
+
payment_method: {
|
95
|
+
card: details.method,
|
96
|
+
billing_details: details.billingDetails,
|
97
|
+
},
|
98
|
+
};
|
99
|
+
}
|
100
|
+
else {
|
101
|
+
cardDetails = {
|
102
|
+
payment_method: details.method,
|
103
|
+
};
|
104
|
+
}
|
105
|
+
if (pay) {
|
106
|
+
((_b = details.billingDetails) === null || _b === void 0 ? void 0 : _b.email) && (cardDetails.receipt_email = details.billingDetails.email);
|
107
|
+
save && (cardDetails.setup_future_usage = 'off_session');
|
108
|
+
stripe.confirmCardPayment(clientSecret, cardDetails).then(resolve).catch(reject);
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
stripe.confirmCardSetup(clientSecret, cardDetails).then(resolve).catch(reject);
|
112
|
+
}
|
113
|
+
}).catch(reject);
|
114
|
+
});
|
115
|
+
}
|
116
|
+
}
|
117
|
+
__decorate([
|
118
|
+
Property({ type: 'object', checkStoredObject: true })
|
119
|
+
], StripeElement.prototype, "options", void 0);
|
120
|
+
__decorate([
|
121
|
+
Property({ type: 'string' })
|
122
|
+
], StripeElement.prototype, "publicKey", void 0);
|
123
|
+
__decorate([
|
124
|
+
Property({ type: 'string' })
|
125
|
+
], StripeElement.prototype, "onready", void 0);
|
126
|
+
__decorate([
|
127
|
+
Property({ type: 'boolean' })
|
128
|
+
], StripeElement.prototype, "defer", void 0);
|
129
|
+
__decorate([
|
130
|
+
Property({ type: 'boolean' })
|
131
|
+
], StripeElement.prototype, "autofocus", void 0);
|
132
|
+
export function StripeElementCompact() {
|
133
|
+
RegisterCustomElement(StripeElement, 'stripe');
|
134
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function InlineJSStripe(): void;
|
package/lib/esm/entry.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { WaitForGlobal } from '@benbraide/inlinejs';
|
2
|
+
import { StripeElementCompact } from './components/stripe';
|
3
|
+
import { StripeFieldElementCompact } from './components/field';
|
4
|
+
import { StripeDetailElementCompact } from './components/detail';
|
5
|
+
import { StripePaymentMenthodElementCompact } from './components/payment-method';
|
6
|
+
export function InlineJSStripe() {
|
7
|
+
WaitForGlobal().then(() => {
|
8
|
+
StripeElementCompact();
|
9
|
+
StripeFieldElementCompact();
|
10
|
+
StripeDetailElementCompact();
|
11
|
+
StripePaymentMenthodElementCompact();
|
12
|
+
});
|
13
|
+
}
|
package/lib/esm/index.d.ts
CHANGED
package/lib/esm/index.js
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
/// <reference types="stripe-v3" />
|
2
|
+
export interface IStripePaymentDetails {
|
3
|
+
method?: stripe.elements.Element | string;
|
4
|
+
billingDetails?: stripe.BillingDetails;
|
5
|
+
}
|
6
|
+
export interface IStripeField {
|
7
|
+
WaitReady(): Promise<void>;
|
8
|
+
ToggleFocus(focused: boolean): void;
|
9
|
+
Reset(): void;
|
10
|
+
AddDetails(details: IStripePaymentDetails): void;
|
11
|
+
}
|
12
|
+
export interface IStripeElement {
|
13
|
+
options: stripe.elements.ElementsOptions | null;
|
14
|
+
AddStripeField(field: IStripeField): void;
|
15
|
+
RemoveStripeField(field: IStripeField): void;
|
16
|
+
FocusNextField(field: IStripeField): void;
|
17
|
+
GetInstance(): stripe.Stripe | null;
|
18
|
+
WaitInstance(): Promise<stripe.Stripe | null>;
|
19
|
+
Mount(): void;
|
20
|
+
}
|
package/lib/esm/types.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@benbraide/inlinejs-stripe",
|
3
|
-
"version": "
|
3
|
+
"version": "2.0.0",
|
4
4
|
"description": "Run javascript code by embedding them in your HTML using the element as context.",
|
5
5
|
"main": "./lib/common/index.js",
|
6
6
|
"module": "./lib/esm/index.js",
|
@@ -17,7 +17,8 @@
|
|
17
17
|
"prepublishOnly": "npm run compile",
|
18
18
|
"build": "webpack -c ./webpack.config.js && webpack -c ./webpack2.config.js",
|
19
19
|
"upload": "npm run build && npm publish --access=public",
|
20
|
-
"
|
20
|
+
"download": "npm i @benbraide/inlinejs @benbraide/inlinejs-element && npm audit fix",
|
21
|
+
"push": "npm run download && npm run upload"
|
21
22
|
},
|
22
23
|
"repository": {
|
23
24
|
"type": "git",
|
@@ -52,7 +53,8 @@
|
|
52
53
|
"webpack": "^5.41.0"
|
53
54
|
},
|
54
55
|
"dependencies": {
|
55
|
-
"@benbraide/inlinejs": "^1.
|
56
|
+
"@benbraide/inlinejs": "^1.1.2",
|
57
|
+
"@benbraide/inlinejs-element": "^2.0.4",
|
56
58
|
"webpack-cli": "^4.7.2"
|
57
59
|
}
|
58
60
|
}
|
package/src/inlinejs-stripe.ts
CHANGED