@infrab4a/connect 5.8.1 → 5.8.3

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": "@infrab4a/connect",
3
- "version": "5.8.1",
3
+ "version": "5.8.3",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -3,7 +3,8 @@ import { Type } from 'class-transformer'
3
3
  import { Shops } from '../../../catalog/models/enums/shops.enum'
4
4
  import { BaseModel, GenericIdentifier } from '../../../generic/model/base.model'
5
5
  import { User, UserAddress } from '../../../users'
6
- import { CardForPaymentInfo, PaymentMethod } from '../../types'
6
+ import { PaymentMethod } from '../../types'
7
+ import { PaymentProvider } from '../../types/payment-provider.type'
7
8
  import { Coupon } from '../coupons/coupon'
8
9
  import { ShoppingRecurrenceCycle } from '../enums/shopping-recurrence-cycle.enum'
9
10
  import { ShoppingRecurrenceStatus } from '../enums/shopping-recurrence-status.enum'
@@ -15,10 +16,10 @@ export class ShoppingRecurrence extends BaseModel<ShoppingRecurrence> {
15
16
  shop: Shops
16
17
  active: boolean
17
18
  status: ShoppingRecurrenceStatus
18
-
19
+
19
20
  recurrenceCycle: ShoppingRecurrenceCycle
20
21
  nextChargeDate: Date
21
-
22
+
22
23
  createdAt: Date
23
24
  updatedAt: Date
24
25
  cancelledAt?: Date
@@ -29,8 +30,11 @@ export class ShoppingRecurrence extends BaseModel<ShoppingRecurrence> {
29
30
  totalPrice: number
30
31
 
31
32
  paymentMethod: PaymentMethod
32
- cards: CardForPaymentInfo[]
33
-
33
+ cards: Array<{
34
+ paymentProvider: PaymentProvider
35
+ cardId: string
36
+ }>
37
+
34
38
  originalOrderId: string
35
39
  lastOrderId?: string
36
40
 
@@ -41,13 +45,13 @@ export class ShoppingRecurrence extends BaseModel<ShoppingRecurrence> {
41
45
 
42
46
  @Type(() => UserAddress)
43
47
  shippingAddress: UserAddress
44
-
48
+
45
49
  @Type(() => UserAddress)
46
50
  billingAddress?: UserAddress
47
-
51
+
48
52
  @Type(() => ShippingMethod)
49
53
  shipping: ShippingMethod
50
-
54
+
51
55
  @Type(() => Coupon)
52
56
  coupon?: Coupon
53
57
 
@@ -118,26 +118,20 @@ export class PagarMeV5RequestHelper {
118
118
  }
119
119
 
120
120
  private static getCardOrder(checkout: Checkout, card: PaymentCardInfo): PagarMeV5OrderPaymentCardInfo {
121
- const billingAddress = {
122
- line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
123
- zip_code: checkout.billingAddress.zip,
124
- city: checkout.billingAddress.city,
125
- state: checkout.billingAddress.state,
126
- country: 'BR',
127
- }
128
-
129
- // Tokenized charges (e.g. shopping recurrence renewals) must not send empty/undefined CVV.
130
- // First checkout still passes cardCvv when the shopper types it.
131
- const cardPayload: PagarMeV5OrderPaymentCardInfo['card'] = {
132
- billing_address: billingAddress,
133
- ...(card.cardCvv ? { cvv: card.cardCvv } : {}),
134
- }
135
-
136
121
  return {
137
122
  installments: card.installments,
138
123
  statement_descriptor: checkout.shop === Shops.GLAMSHOP ? 'loja glam' : 'mens market',
139
124
  card_id: card.cardId,
140
- card: cardPayload,
125
+ card: {
126
+ cvv: card.cardCvv,
127
+ billing_address: {
128
+ line_1: `${checkout.billingAddress.number}, ${checkout.billingAddress.street}, ${checkout.billingAddress.district}`,
129
+ zip_code: checkout.billingAddress.zip,
130
+ city: checkout.billingAddress.city,
131
+ state: checkout.billingAddress.state,
132
+ country: 'BR',
133
+ },
134
+ },
141
135
  }
142
136
  }
143
137
 
@@ -71,8 +71,7 @@ export type PagarMeV5OrderPaymentCardInfo = {
71
71
  statement_descriptor: string
72
72
  card_id: string
73
73
  card: {
74
- /** Present only on first charge when the shopper types CVV. Omitted for tokenized renewals. */
75
- cvv?: string
74
+ cvv: string
76
75
  billing_address?: {
77
76
  line_1: string
78
77
  zip_code: string
@@ -1,77 +0,0 @@
1
- import { Checkout, PaymentCardInfo, PaymentProviders, Shops } from '../../../../domain'
2
-
3
- import { PagarMeV5RequestHelper } from './pagarme-v5-request.helper'
4
-
5
- describe('PagarMeV5RequestHelper', () => {
6
- const buildCheckout = (): Checkout =>
7
- ({
8
- shop: Shops.GLAMSHOP,
9
- totalPrice: 110,
10
- user: {
11
- displayName: 'Ada Lovelace',
12
- email: 'ada@example.com',
13
- cpf: '12345678901',
14
- phone: '11999999999',
15
- isSubscriber: false,
16
- },
17
- lineItems: [{ name: 'Item', pricePaid: 100, quantity: 1, EAN: '123', isGift: false }],
18
- shipping: { ShippingPrice: 10, ShippingCompanyName: 'Carrier', description: 'PAC' },
19
- billingAddress: {
20
- number: '10',
21
- street: 'Rua A',
22
- district: 'Centro',
23
- zip: '01310100',
24
- city: 'São Paulo',
25
- state: 'SP',
26
- extension: '',
27
- },
28
- shippingAddress: {
29
- number: '10',
30
- street: 'Rua A',
31
- district: 'Centro',
32
- zip: '01310100',
33
- city: 'São Paulo',
34
- state: 'SP',
35
- extension: '',
36
- recipient: 'Ada',
37
- },
38
- }) as Checkout
39
-
40
- const buildCard = (overrides: Partial<PaymentCardInfo> = {}): PaymentCardInfo => ({
41
- cardId: 'card_abc',
42
- paymentProvider: PaymentProviders.PAGARME,
43
- installments: 1,
44
- ...overrides,
45
- })
46
-
47
- it('should omit cvv when cardCvv is absent on credit_card payment', () => {
48
- const payload = PagarMeV5RequestHelper.build(buildCheckout(), 'credit_card', buildCard())
49
- const creditCard = payload.payments[0].credit_card
50
-
51
- expect(creditCard?.card_id).toBe('card_abc')
52
- expect(creditCard?.card.billing_address?.zip_code).toBe('01310100')
53
- expect(creditCard?.card).not.toHaveProperty('cvv')
54
- })
55
-
56
- it('should include cvv when cardCvv is provided', () => {
57
- const payload = PagarMeV5RequestHelper.build(
58
- buildCheckout(),
59
- 'credit_card',
60
- buildCard({ cardCvv: '123' }),
61
- )
62
- const creditCard = payload.payments[0].credit_card
63
-
64
- expect(creditCard?.card.cvv).toBe('123')
65
- })
66
-
67
- it('should omit cvv when cardCvv is empty string', () => {
68
- const payload = PagarMeV5RequestHelper.build(
69
- buildCheckout(),
70
- 'credit_card',
71
- buildCard({ cardCvv: '' }),
72
- )
73
- const creditCard = payload.payments[0].credit_card
74
-
75
- expect(creditCard?.card).not.toHaveProperty('cvv')
76
- })
77
- })