activemerchant / active_merchant

Active Merchant is a simple payment abstraction library extracted from Shopify. The aim of the project is to feel natural to Ruby users and to abstract as many parts as possible away from the user to offer a consistent interface across all supported gateways.
http://activemerchant.org
MIT License
4.54k stars 2.5k forks source link

Pagar.me gateway: transactions are failing due to invalid card_expiration_date format #2534

Open vitork opened 7 years ago

vitork commented 7 years ago

I'm trying to integrate a store application with the Pagar.me gateway using ActiveMerchant 1.69.0 but all transactions are failing with an error in the card_expiration_date parameter.

This is happening probably because of a change in the /transactions API. I checked the docs and found out the endpoint accepts card_expiration_date in the format MMYY (I tried with MMYYYY and also worked), rather than MM/YY.

https://docs.pagar.me/reference#criar-transacao

Steps to reproduce:

gateway = ActiveMerchant::Billing::PagarmeGateway.new(api_key: my_api_key)

cc = ActiveMerchant::Billing::CreditCard.new(
  number: "4242424242424242",
  month: 12,
  year: 2020,
  verification_value: "123",
  first_name: "Tom",
  last_name: "Jobim"
)

response = gateway.purchase(1000, cc)
=> #<ActiveMerchant::Billing::Response:0x007fcdbdb44500 @params={"errors"=>[{"parameter_name"=>"card_expiration_date", "type"=>"invalid_parameter", "message"=>"Data de expiração inválida"}], "url"=>"/transactions", "method"=>"post"}, @message="Data de expiração inválida", @success=false, @test=true, @authorization=nil, @fraud_review=nil, @error_code="processing_error", @emv_authorization=nil, @avs_result={"code"=>nil, "message"=>nil, "street_match"=>nil, "postal_match"=>nil}, @cvv_result={"code"=>nil, "message"=>nil}>

After I remove the slash:

response = gateway.purchase(1000, cc)
=> #<ActiveMerchant::Billing::Response:0x007fa8fe8145f8 @params={"object"=>"transaction", "status"=>"paid", "refuse_reason"=>nil, "status_reason"=>"acquirer", "acquirer_response_code"=>"00", "acquirer_name"=>"development", "acquirer_id"=>"1234", "authorization_code"=>"530022", "soft_descriptor"=>nil, "tid"=>"1790259", "nsu"=>nil, "date_created"=>"2017-08-03T21:53:44.767Z", "date_updated"=>"2017-08-03T21:53:44.961Z", "amount"=>1000, "authorized_amount"=>1000, "paid_amount"=>1000, "refunded_amount"=>0, "installments"=>1, "id"=>1790259, "cost"=>65, "card_holder_name"=>"Tom Jobim", "card_last_digits"=>"4242", "card_first_digits"=>"424242", "card_brand"=>"visa", "card_pin_mode"=>nil, "postback_url"=>nil, "payment_method"=>"credit_card", "capture_method"=>"ecommerce", "antifraud_score"=>nil, "boleto_url"=>nil, "boleto_barcode"=>nil, "boleto_expiration_date"=>nil, "referer"=>"api_key", "ip"=>"10.2.13.21", "subscription_id"=>nil, "phone"=>nil, "address"=>nil, "customer"=>nil, "billing"=>nil, "shipping"=>nil, "items"=>[], "card"=>{"object"=>"card", "id"=>"card_cj5wzaiwj00ukqb6dwxkai1iv", "date_created"=>"2017-08-03T21:53:44.756Z", "date_updated"=>"2017-08-03T21:53:45.010Z", "brand"=>"visa", "holder_name"=>"Tom Jobim", "first_digits"=>"424242", "last_digits"=>"4242", "country"=>"UNITED STATES", "fingerprint"=>"1234", "valid"=>true, "expiration_date"=>"1220"}, "split_rules"=>nil, "metadata"=>{}, "antifraud_metadata"=>{}, "reference_key"=>nil}, @message="Transação aprovada", @success=true, @test=true, @authorization=1790259, @fraud_review=nil, @error_code=nil, @emv_authorization=nil, @avs_result={"code"=>nil, "message"=>nil, "street_match"=>nil, "postal_match"=>nil}, @cvv_result={"code"=>nil, "message"=>nil}>
kaiomagalhaes commented 6 years ago

@vitork any news on this?

bpollack commented 6 years ago

We'd be happy to accept a PR for this.