@live-change/stripe-service 0.8.110 → 0.8.111

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/stripe-service",
3
- "version": "0.8.110",
3
+ "version": "0.8.111",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -21,14 +21,14 @@
21
21
  "url": "https://www.viamage.com/"
22
22
  },
23
23
  "dependencies": {
24
- "@live-change/framework": "^0.8.110",
25
- "@live-change/relations-plugin": "^0.8.110",
24
+ "@live-change/framework": "^0.8.111",
25
+ "@live-change/relations-plugin": "^0.8.111",
26
26
  "lru-cache": "^7.12.0",
27
27
  "pluralize": "^8.0.0",
28
28
  "progress-stream": "^2.0.0",
29
29
  "prosemirror-model": "^1.18.1",
30
30
  "stripe": "^17.2.1"
31
31
  },
32
- "gitHead": "8af31d640f43b00b2874f2c70fa4d4486541adfe",
32
+ "gitHead": "9b96afb2fc61ab3d2a5d143924e2c56d411280b4",
33
33
  "type": "module"
34
34
  }
package/payment.js CHANGED
@@ -7,35 +7,35 @@ import config from './config.js'
7
7
  import stripe from "./stripeClient.js"
8
8
 
9
9
  const itemsArray = {
10
- type: Array,
11
- of: {
12
- type: Object,
13
- properties: {
14
- name: {
15
- type: String,
16
- validation: ['nonEmpty']
17
- },
18
- price: {
19
- type: Number,
20
- validation: ['nonEmpty', 'number']
21
- },
22
- currency: {
23
- type: String,
24
- validation: ['nonEmpty']
25
- },
26
- quantity: {
27
- type: Number,
28
- validation: ['nonEmpty', 'number']
29
- },
30
- description: {
31
- type: String
32
- },
33
- taxCode: {
34
- type: String
35
- }
10
+ type: Array,
11
+ of: {
12
+ type: Object,
13
+ properties: {
14
+ name: {
15
+ type: String,
16
+ validation: ['nonEmpty']
17
+ },
18
+ price: {
19
+ type: Number,
20
+ validation: ['nonEmpty', 'number']
21
+ },
22
+ currency: {
23
+ type: String,
24
+ validation: ['nonEmpty']
25
+ },
26
+ quantity: {
27
+ type: Number,
28
+ validation: ['nonEmpty', 'number']
29
+ },
30
+ description: {
31
+ type: String
32
+ },
33
+ taxCode: {
34
+ type: String
36
35
  }
37
36
  }
38
37
  }
38
+ }
39
39
 
40
40
  const paymentParameters = {
41
41
  items: itemsArray,
@@ -90,12 +90,14 @@ definition.trigger({
90
90
  properties: {
91
91
  ...paymentParameters
92
92
  },
93
- waitForEvents:true,
93
+ waitForEvents: true,
94
94
  async execute({ items, causeType, cause, successUrl, cancelUrl, payerType, payer }, { service }, emit) {
95
95
  const payment = app.generateUid()
96
+ if(!successUrl) successUrl = config.checkoutSuccessUrl + '/' + payment.replace(/\[/g, '(').replace(/]/g, ')')
97
+ if(!cancelUrl) cancelUrl = config.checkoutCancelUrl + '/' + payment.replace(/\[/g, '(').replace(/]/g, ')')
96
98
  console.log("URLS", {
97
- success_url: successUrl ?? (config.checkoutSuccessUrl + '/' + payment),
98
- cancel_url: cancelUrl ?? (config.checkoutCancelUrl + '/' + payment)
99
+ success_url: successUrl,
100
+ cancel_url: cancelUrl,
99
101
  })
100
102
  const metadata = {
101
103
  type: 'payment',
@@ -128,14 +130,15 @@ definition.trigger({
128
130
  metadata
129
131
  },
130
132
  mode: 'payment',
131
- success_url: successUrl ?? (config.checkoutSuccessUrl + '/' + payment),
132
- cancel_url: cancelUrl ?? (config.checkoutCancelUrl + '/' + payment)
133
+ success_url: successUrl,
134
+ cancel_url: cancelUrl,
133
135
  })
134
136
  emit({
135
137
  type: 'PaymentCreated',
136
138
  payment,
137
139
  data: {
138
140
  items, causeType, cause, payerType, payer,
141
+ successUrl, cancelUrl,
139
142
  stripeSession: session.id,
140
143
  state: 'created'
141
144
  }
@@ -147,3 +150,4 @@ definition.trigger({
147
150
  }
148
151
  }
149
152
  })
153
+
package/stripeEvents.js CHANGED
@@ -8,13 +8,6 @@ import stripe from "./stripeClient.js"
8
8
 
9
9
  import { Payment } from './payment.js'
10
10
 
11
-
12
- /// TODO: obsługa zdarzeń:
13
- /// dla stanu płatności:
14
- /// charge.succeeded
15
- /// charge.refunded
16
-
17
-
18
11
  definition.trigger({
19
12
  name: 'stripeEvent.checkout.session.completed',
20
13
  properties: {
@@ -42,6 +35,7 @@ definition.trigger({
42
35
  const payment = await Payment.get(referenceId)
43
36
  if(!payment) throw new Error('Payment '+referenceId+' not found')
44
37
  if(object.payment_status === 'paid') {
38
+ console.log("PAYMENT TO UPDATE", payment)
45
39
  await triggerService({
46
40
  service: definition.name,
47
41
  type: 'stripe_updatePayment'
@@ -50,6 +44,7 @@ definition.trigger({
50
44
  state: 'succeeded'
51
45
  })
52
46
  const triggerData = {
47
+ paymentType: 'stripe_Payment',
53
48
  payment: referenceId,
54
49
  causeType: payment.causeType,
55
50
  cause: payment.cause,
@@ -113,6 +108,7 @@ definition.trigger({
113
108
  state: 'failed'
114
109
  })
115
110
  const triggerData = {
111
+ paymentType: 'stripe_Payment',
116
112
  payment: referenceId,
117
113
  causeType: payment.causeType,
118
114
  cause: payment.cause,
@@ -168,6 +164,7 @@ definition.trigger({
168
164
  state: 'succeeded'
169
165
  })
170
166
  const triggerData = {
167
+ paymentType: 'stripe_Payment',
171
168
  payment: referenceId,
172
169
  causeType: payment.causeType,
173
170
  cause: payment.cause,
@@ -230,6 +227,7 @@ definition.trigger({
230
227
  state: 'failed'
231
228
  })
232
229
  const triggerData = {
230
+ paymentType: 'stripe_Payment',
233
231
  payment: referenceId,
234
232
  causeType: payment.causeType,
235
233
  cause: payment.cause,
@@ -267,6 +265,7 @@ definition.trigger({
267
265
  if(object.metadata?.type === 'payment') {
268
266
  const payment = await Payment.get(object.metadata.payment)
269
267
  const triggerData = {
268
+ paymentType: 'stripe_Payment',
270
269
  payment: payment.id,
271
270
  causeType: payment.causeType,
272
271
  cause: payment.cause,
@@ -303,6 +302,7 @@ definition.trigger({
303
302
  if(object.metadata?.type === 'payment') {
304
303
  const payment = await Payment.get(object.metadata.payment)
305
304
  const triggerData = {
305
+ paymentType: 'stripe_Payment',
306
306
  payment: payment.id,
307
307
  causeType: payment.causeType,
308
308
  cause: payment.cause,
package/webhook.js CHANGED
@@ -3,13 +3,12 @@ const app = App.app()
3
3
  import definition from './definition.js'
4
4
  import config from './config.js'
5
5
 
6
+ import { encodeDate } from "@live-change/uid"
7
+
6
8
  import crypto from "crypto"
7
9
  import express from "express"
8
10
  import stripe from "stripe"
9
11
 
10
-
11
-
12
-
13
12
  definition.endpoint({
14
13
  name: 'webhook',
15
14
  create() {
@@ -24,10 +23,13 @@ definition.endpoint({
24
23
  try {
25
24
  const signature = request.headers['stripe-signature']
26
25
  const event = stripe.webhooks.constructEvent(request.body, signature, config.webhookSecret)
27
- console.log("STRIPE WEBHOOK", event.type )//,JSON.stringify(event))
26
+ console.log("STRIPE WEBHOOK", event.type)//, JSON.stringify(event))
27
+ const { id, created } = event
28
+ const eventIdEncoded = `[${encodeDate(new Date(created*1000))}.${id}@stripe]`
28
29
  await app.trigger({
29
30
  // service: 'stripe',
30
- type: `stripeEvent.${event.type}`
31
+ type: `stripeEvent.${event.type}`,
32
+ id: eventIdEncoded // needed for deduplication
31
33
  }, {
32
34
  ...event
33
35
  })