This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: promotion based on Pagar.me paymentMethod
- Loading branch information
Showing
3 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './payment-method-handler'; | ||
export * from './promotion-action'; | ||
export * from './plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { PromotionOrderAction, LanguageCode } from '@vendure/core'; | ||
|
||
export const pagarmeBoletoPromotionAction = new PromotionOrderAction({ | ||
code: 'pagarme-boleto-discount', | ||
args: { | ||
discount: { | ||
type: 'int' | ||
} | ||
}, | ||
execute(order, args) { | ||
// @ts-ignore | ||
const paymentMethod = order.customFields.pagarmePaymentMethod; | ||
if (paymentMethod && paymentMethod === 'boleto') { | ||
return -order.subTotal * (args.discount / 100); | ||
} | ||
return order.subTotal; | ||
}, | ||
description: [ | ||
{ | ||
languageCode: LanguageCode.en, | ||
value: | ||
'Discount of {discount}% on the order with boleto payment method in Pagar.me' | ||
}, | ||
{ | ||
languageCode: LanguageCode.pt_BR, | ||
value: | ||
'Desconto de {discount}% no pedido no método de pagamento boleto usando o Pagar.me' | ||
} | ||
] | ||
}); | ||
|
||
export const pagarmeCreditCardPromotionAction = new PromotionOrderAction({ | ||
code: 'pagarme-credit-card-discount', | ||
args: { | ||
discount: { | ||
type: 'int' | ||
} | ||
}, | ||
execute(order, args) { | ||
// @ts-ignore | ||
const paymentMethod = order.customFields.pagarmePaymentMethod; | ||
if (paymentMethod && paymentMethod === 'credit_card') { | ||
return -order.subTotal * (args.discount / 100); | ||
} | ||
return order.subTotal; | ||
}, | ||
description: [ | ||
{ | ||
languageCode: LanguageCode.en, | ||
value: | ||
'Discount of {discount}% on the order with credit card payment method in Pagar.me' | ||
}, | ||
{ | ||
languageCode: LanguageCode.pt_BR, | ||
value: | ||
'Desconto de {discount}% no pedido no método de pagamento cartão de crédito usando o Pagar.me' | ||
} | ||
] | ||
}); |