Skip to content

Instantly share code, notes, and snippets.

@abelorian
Last active June 22, 2018 17:29
Show Gist options
  • Save abelorian/89b6b33783a47f7a380a141d1db90381 to your computer and use it in GitHub Desktop.
Save abelorian/89b6b33783a47f7a380a141d1db90381 to your computer and use it in GitHub Desktop.
Conekta - Pagos con Tarjeta
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