Last active
June 22, 2018 17:29
-
-
Save abelorian/89b6b33783a47f7a380a141d1db90381 to your computer and use it in GitHub Desktop.
Conekta - Pagos con Tarjeta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "conekta" | |
Conekta.api_key = "key_mkdVk1gAJEDrqbgie7wmwA" | |
Conekta.api_version = "2.0.0" | |
customer = Conekta::Customer.create({ | |
:name => 'Paying User', | |
:email => '[email protected]', | |
:phone => '+52181818181', | |
:payment_sources => [{ | |
:type => 'card', | |
:token_id => 'tok_test_visa_4242' | |
}] | |
}) | |
begin | |
order = Conekta::Order.create({ | |
:line_items => [{ | |
:name => "Tacos", | |
:unit_price => 1000, | |
:quantity => 12 | |
}], #line_items | |
:shipping_lines => [{ | |
:amount => 1500, | |
:carrier => "FEDEX" | |
}], #shipping_lines - physical goods only | |
:currency => "MXN", | |
:customer_info => { | |
:customer_id => customer.id | |
}, #customer_info | |
:shipping_contact => { | |
:address => { | |
:street1 => "Calle 123, int 2", | |
:postal_code => "06100", | |
:country => "MX" | |
} | |
}, #shipping_contact - required only for physical goods | |
:charges => [{ | |
:reference_id => "I'm a reference :)", | |
:payment_method => { | |
:type => "default" | |
} #payment_method - use the customer's default - a card | |
#to charge a card, different from the default, | |
#you can indicate the card's source_id as shown in the Retry Card Section | |
}], | |
:metadata => {"reference" => "12987324097", "more_info" => "lalalalala"} | |
}) | |
rescue Conekta::ErrorList => error_list | |
for error_detail in error_list.details do | |
puts error_detail.message | |
end | |
end | |
# Opción 2 - Datos de comprador en una sola llamada | |
require "conekta" | |
Conekta.api_key = "key_mkdVk1gAJEDrqbgie7wmwA" | |
Conekta.api_version = "2.0.0" | |
begin | |
order = Conekta::Order.create({ | |
:line_items => [{ | |
:name => "Tacos", | |
:unit_price => 1000, | |
:quantity => 12 | |
}], #line_items | |
:shipping_lines => [{ | |
:amount => 1500, | |
:carrier => "FEDEX" | |
}], #shipping_lines - physical goods only | |
:currency => "MXN", | |
:customer_info => { | |
:name => 'Paying User', | |
:email => '[email protected]', | |
:phone => '+52181818181' | |
}, #customer_info | |
:shipping_contact => { | |
:address => { | |
:street1 => "Calle 123, int 2", | |
:postal_code => "06100", | |
:country => "MX" | |
} | |
}, #shipping_contact - required only for physical goods | |
:charges => [{ | |
:reference_id => "I'm a reference :)", | |
:payment_method => { | |
:type => "card", | |
:token_id => "tok_test_visa_4242" | |
} #payment_method - use the customer's default - a card | |
#to charge a card, different from the default, | |
#you can indicate the card's source_id as shown in the Retry Card Section | |
}], | |
:metadata => {"reference" => "12987324097", "more_info" => "lalalalala"} | |
}) | |
rescue Conekta::ErrorList => error_list | |
for error_detail in error_list.details do | |
puts error_detail.message | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment