2012-12-20 4 views
8

SfondoPaymill: come si simula un pagamento non riuscito durante il test?

Domanda

Come faccio a fare un pagamento di prova? (Per esempio carta viene rifiutata, o la scheda è scaduto nel pagamento di abbonamento futuri)

Stripe would let me do this using special card numbers ma ci non sembra essere tale documentazione (in inglese) per Paymill.


payment_provider.rb

class PaymentProvider 
    Paymill.api_key = ENV['PAYMILL_PRIVATE_KEY'] 

    def self.start_new_subscription(email, description, token) 
    offer = Paymill::Offer.find(ENV['PAYMILL_OFFER_ID']) 
    client = Paymill::Client.create(email: email, description: description) 
    payment = Paymill::Payment.create(token: token, client: client.id) 
    subscription = Paymill::Subscription.create(client: client.id, offer: offer.id, payment: payment.id) 
    subscription.id 
    end 
end 


payment_provider_spec.rb

require 'spec_helper' 

describe PaymentProvider do 

    describe "#start_new_subscription" do 
    it "returns a subscription id, starting 'sub_' when successful" do 
     email = "[email protected]" 
     description = "me" 
     token = get_payment_token 
     subscription_id = PaymentProvider.start_new_subscription(email, description, token) 
     expect(subscription_id[0,4]).to eq('sub_') 
    end 
    end 

    def get_payment_token 
    # Simulate the JavaScript bridge we would use in production 
    params = { 
     'transaction.mode'  => 'CONNECTOR_TEST', 
     'channel.id'    => ENV['PAYMILL_PUBLIC_KEY'], 
     'jsonPFunction'   => 'any_string', 
     'account.number'   => '5500000000000004', 
     'account.expiry.month' => 3.years.from_now.month, 
     'account.expiry.year'  => 3.years.from_now.year, 
     'account.verification' => '111' 
     #'presentation.amount3D' => BigDecimal('10.00'), 
     #'presentation.currency3D' => 'GBP' 
    } 
    http = Net::HTTP.new('test-token.paymill.de', 443) 
    http.use_ssl = true 
    response = http.get url_query_string(params) 
    response.body.scan(/tok_\w*\b/).first # Use a regex to pull the token from the (not-quite-JSON) response 
    end 

    def url_query_string(hash) 
    "/?" << URI.escape(hash.collect{|k,v| "#{k}=#{v}"}.join('&')) 
    end 

end 

risposta

4

Ad oggi, non ci sono numeri di carte di credito speciali per simulare questi problemi. Tuttavia, a causa delle richieste della comunità, questo è attualmente nel backlog per essere implementato. Suggerirei di inviare un'e-mail al supporto, per mostrare interesse su questa funzionalità. Più richieste vengono richieste, più velocemente sarà implementata la funzione.

MODIFICA: PAYMILL ora offre uno speciale numero di MasterCard, che fallirà se verrà utilizzata una determinata combinazione di mese e anno di scadenza. Ad esempio, la scheda 5105105105105100 non funzionerà a causa di RESPONSE_BACKEND_BLACKLISTED se la data di scadenza viene inviata come 02/2020.

+0

L'elenco completo di combinazioni per date di scadenza e codici di errore può essere trovato qui: https://developers.paymill.com/guides/reference/testing#how-do-i-test-credit-card-specific-error -codes- – LeEnno

0

Quello che potresti fare è usare una stringa piuttosto che un numero per il valore di verifica.

'account.verification' => 'abc' 

Questa volontà come di mio risultato conoscenze in un mancato pagamento anche quando si utilizza la modalità CONNECTOR_TEST.

Problemi correlati