Skip to content

Commit 0cedc27

Browse files
committed
chore(payment-subscriptions): add field to credit card
1 parent a21e17d commit 0cedc27

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

functions/routes/ecom/modules/create-transaction.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ exports.post = ({ appSdk }, req, res) => {
1111

1212
const orderId = params.order_id
1313
const { amount, buyer, payer, to, items } = params
14-
console.log('> Transaction #', storeId, orderId)
14+
console.log(`> Transaction #${storeId}, ${orderId}`)
1515
let quantityItems = 0
1616

1717
// https://apx-mods.e-com.plus/api/v1/create_transaction/response_schema.json?store_id=100
@@ -45,7 +45,9 @@ exports.post = ({ appSdk }, req, res) => {
4545
payment_method: 'credit_card',
4646
amount: Math.floor(finalAmount * 100),
4747
installments: installmentsNumber,
48-
card_hash: params.credit_card && params.credit_card.hash
48+
card_hash: params.credit_card && params.credit_card.hash,
49+
recurrence_model: installmentsNumber ? 'installment' : 'standing_order',
50+
initiated_type: 'PartialShipment'
4951
}
5052
} else if (params.payment_method.code === 'account_deposit') {
5153
const finalAmount = amount.total
@@ -82,7 +84,7 @@ exports.post = ({ appSdk }, req, res) => {
8284
const parseDatePagarme = ms => {
8385
const timeMs = ms.getTime() - (180000 * 60)
8486
const newDate = new Date(timeMs)
85-
const pad = n => `${Math.floor(Math.abs(n))}`.padStart(2, '0');
87+
const pad = n => `${Math.floor(Math.abs(n))}`.padStart(2, '0')
8688
return date.getFullYear() +
8789
'-' + pad(newDate.getMonth() + 1) +
8890
'-' + pad(newDate.getDate())
@@ -154,7 +156,7 @@ exports.post = ({ appSdk }, req, res) => {
154156
address: parseAddress(params.billing_address)
155157
}
156158
}
157-
159+
158160
pagarmeTransaction.items = []
159161
items.forEach(item => {
160162
if (item.quantity > 0) {
@@ -201,7 +203,7 @@ exports.post = ({ appSdk }, req, res) => {
201203
if (data.customer && data.customer.id) {
202204
transaction.intermediator.buyer_id = String(data.customer.id)
203205
}
204-
206+
205207
if (transaction.banking_billet) {
206208
if (data.boleto_barcode) {
207209
transaction.banking_billet.code = data.boleto_barcode
@@ -230,14 +232,15 @@ exports.post = ({ appSdk }, req, res) => {
230232
}
231233
}
232234
}
233-
235+
234236
transaction.status = {
237+
// eslint-disable-next-line promise/always-return
235238
updated_at: data.date_created || data.date_updated || new Date().toISOString(),
236239
current: parseStatus(data.status)
237240
}
238241
res.send({ transaction })
239242
})
240-
243+
241244
.catch(error => {
242245
console.log(error)
243246
// try to debug request error

0 commit comments

Comments
 (0)