oBraspag is a simple gem to use Braspag Gateway.
gem 'obraspag', :git => 'git@github.com:olook/obraspag.git', :branch => 'master'
rails generate braspag:install
If you have different ambience, you have to copy configs staging: environment: "homologation" merchant_id: "YOUR MERCHANT ID"
Method Authorize
order = Braspag::Order.new(0006, RAILS_ENV) address = Braspag::AddressBuilder.new.with_street("Rua dos Alfeneiros").with_number("123") .with_complement("").with_district("Pinheiros") .with_zip_code("05425-070").with_city("Sao Paulo") .with_state("SP").with_country("Brasil").build customer = Braspag::CustomerBuilder.new.with_customer_id("1234") .with_customer_name("John") .with_customer_email("somebody@somedomain.com") .with_customer_address(address).with_delivery_address(address).build payment_request = Braspag::CreditCardBuilder.new.with_payment_method(Braspag::PAYMENT_METHOD[:braspag]) .with_amount("500").with_transaction_type("1").with_currency("BRL").with_country("BRA") .with_number_of_payments(1).with_payment_plan("0").with_transaction_type("1") .with_holder_name("Comprador Teste").with_card_number("0000000000000001") .with_security_code("123").with_expiration_month("05").with_expiration_year("2018").build request = Braspag::AuthorizeTransactionRequestBuilder.new .with_request_id("00000000-0000-0000-0000-000000000007") .for_order(order).for_customer(customer).with_payment_request(payment_request).build webservice = Braspag::Webservice.new(:homolog) webservice.authorize_transaction(request)
Method Capture
transaction_request = Braspag::TransactionRequest.new("540BA6EE-39D7-3DC1-D87D-7F82C49A3598", "500") request = Braspag::CreditCardTransactionRequestBuilder .new.with_request_id("00000000-0000-0000-0000-000000000007") .with_transaction_request(transaction_request).build webservice = Braspag::Webservice.new(:homolog) webservice.capture_credit_card_transaction(request)
Method Void
supose that you make authorize method that return on hash:
BraspagTransactionId: "11111111-1111-1111-1111-111111111111"
transaction_request = Braspag::TransactionRequest.new("1111111-1111-1111-1111-111111111111")
request = Braspag::CreditCardTransactionRequestBuilder.new
.with_request_id("00000000-0000-0000-0000-000000000009")
.with_transaction_data_collection(transaction_request).build
webservice = Braspag::Webservice.new(:homolog)
webservice.void_credit_card_transaction(request)