feat: the Site takes credit card and PIX only, no debit
Dropstar does not take debit cards, and Mercado Pago never enabled debit on the account, so a customer who chose "Cartão de débito" met an error. The payment page offers credit card and PIX, the card form accepts only credit cards, and the server refuses a debit method sent around the page. The adapter still knows how to pay by debit, should it be offered again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -201,6 +201,11 @@ class PaymentMethod(StrictModel):
|
||||
def card_needs_token(self):
|
||||
if self.type == 'card' and not (self.token and self.payment_method_id):
|
||||
raise ValueError('Card payment requires the provider token and method')
|
||||
# The store takes credit cards and PIX only. Mercado Pago's debit
|
||||
# methods are debvisa, debmaster, debelo...; the adapter still knows
|
||||
# how to pay one, should debit be offered again.
|
||||
if self.type == 'card' and self.payment_method_id.startswith('deb'):
|
||||
raise ValueError('Só aceitamos cartão de crédito ou PIX.')
|
||||
return self
|
||||
|
||||
class PaymentIntent(StrictModel):
|
||||
|
||||
@@ -58,6 +58,10 @@ def run():
|
||||
assert not customer.call('/quotes/' + quote_id)['order'], 'unsigned delivery created an order'
|
||||
print('PASS: unsigned and tampered deliveries are refused and create nothing')
|
||||
|
||||
# Debit cards are not taken, even sent around the payment page.
|
||||
customer.call('/payments/intent', {'quote_id': quote_id, 'method': {
|
||||
'type': 'card', 'token': 'tok', 'payment_method_id': 'debvisa'}}, expected=422)
|
||||
|
||||
# Starting a PIX twice returns the same one. A card in review blocks every
|
||||
# further attempt, so one quote can never be charged twice.
|
||||
pix = customer.call('/payments/intent', {'quote_id': quote_id, 'method': {'type': 'pix'}})
|
||||
|
||||
@@ -439,7 +439,8 @@
|
||||
// Paying: card (the default, paid on this page) or PIX (paid on its own page).
|
||||
async function escolhaPagamento(quote, version) {
|
||||
const session=await ready;
|
||||
const opcoes=[...(session.payment_public_key?[['credito','Cartão de crédito'],['debito','Cartão de débito']]:[]),['pix','PIX']];
|
||||
// Credit card and PIX: the store does not take debit cards.
|
||||
const opcoes=[...(session.payment_public_key?[['credito','Cartão de crédito']]:[]),['pix','PIX']];
|
||||
let escolhido=opcoes[0][0];
|
||||
const grupo=node('div',null,'metodos');
|
||||
grupo.setAttribute('role','radiogroup'); grupo.setAttribute('aria-label','Forma de pagamento');
|
||||
@@ -454,7 +455,7 @@
|
||||
async function pinta() {
|
||||
radios.forEach(el=>el.setAttribute('aria-checked',String(el.dataset.metodo===escolhido)));
|
||||
unmountCard(); area.replaceChildren(); message('');
|
||||
if (escolhido!=='pix') { await showCard(quote.approved, area, version, escolhido); return; }
|
||||
if (escolhido!=='pix') { await showCard(quote.approved, area, version); return; }
|
||||
area.append(node('p','Clique em Pagar para gerar o QR code do PIX.','pagNota'));
|
||||
button('Pagar',async event=>{
|
||||
if (!cartOk()) { await refresh(); return; }
|
||||
@@ -550,7 +551,7 @@
|
||||
function unmountCard() {
|
||||
if (cardBrick) { try { cardBrick.unmount(); } catch(_) {} cardBrick=null; }
|
||||
}
|
||||
async function showCard(approved, into, version, tipo) {
|
||||
async function showCard(approved, into, version) {
|
||||
const holder=node('div');
|
||||
holder.id='cardPaymentBrick';
|
||||
const espera=node('div',null,'skel skelBloco');
|
||||
@@ -564,10 +565,8 @@
|
||||
const mp=new window.MercadoPago(session.payment_public_key,{locale:'pt-BR'});
|
||||
cardBrick=await mp.bricks().create('cardPayment','cardPaymentBrick',{
|
||||
initialization:{amount:approved.total_cents/100, payer:{email:approved.customer.mail}},
|
||||
// Each option takes only its kind of card; debit is paid at once.
|
||||
customization:{paymentMethods:tipo==='debito'
|
||||
? {maxInstallments:1,types:{excluded:['credit_card']}}
|
||||
: {maxInstallments:12,types:{excluded:['debit_card']}},
|
||||
// Credit cards only: the store does not take debit.
|
||||
customization:{paymentMethods:{maxInstallments:12,types:{excluded:['debit_card']}},
|
||||
// The option above already names the card; the form's own title
|
||||
// ("crédito ou débito") would contradict it.
|
||||
visual:{hideFormTitle:true,
|
||||
|
||||
Reference in New Issue
Block a user