Arka PlanÖmrü: Test ederken başarısız bir ödemeyi nasıl taklit edebilirim?
- Paymill's subscription billing özelliğini kullanarak bir uygulama geliştirme.
- Ruby wrapper'u kullanarak, aşağıdaki gibi bir
PaymentProvider
sınıf ve spec oluşturduk.
Soru
nasıl bir test ödemesi başarısız yapabilirim? Paymill için (örneğin kart reddedilirse veya kart gelecekteki abonelik ödemeleri ayında sona ermişti)
Stripe would let me do this using special card numbers ancak (İngilizce) bu tür belgeler orada görünmüyor.
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 Bugün itibariyle
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
Son kullanma tarihleri ve hata kodları için kombinasyonların tam listesi şu adreste bulunabilir: https://developers.paymill.com/guides/reference/testing#how-do-i-test-credit-card-specific-error -codes- – LeEnno