Skip to content

Instantly share code, notes, and snippets.

@electronicbites
Created September 19, 2015 11:55
Show Gist options
  • Save electronicbites/3050055ef5869b878052 to your computer and use it in GitHub Desktop.
Save electronicbites/3050055ef5869b878052 to your computer and use it in GitHub Desktop.
mangopay sample
#create mango pay user (dummy)
user_id = begin
mango_user = MangoPay::NaturalUser.create({'FirstName' => 'DummyFirstName', 'LastName' => 'DummyLastName',
'Email' => '[email protected]', 'Birthday' => 1300186358,
'Nationality' => FFaker::Address.country_code,
'CountryOfResidence' => FFaker::Address.country_code,
'Tag' => "Guest of #{@restaurant.name}"})
mango_user['Id']
rescue SocketError => e
'-1'
end
card_data = MangoPay::CardRegistration.create({UserId: user_id, Currency: 'EUR', Tag: 'Inicat User'})
==> JavaScript
var cardInitData = {
cardRegistrationURL: "#{card_data['CardRegistrationURL']}",
preregistrationData: "#{card_data['PreregistrationData']}",
accessKey: "#{card_data['AccessKey']}",
Id: "#{card_data['Id']}"
}
<% if Rails.env.production? %>
mangoPay.cardRegistration.baseURL = "https://api.mangopay.com"
<% else %>
mangoPay.cardRegistration.baseURL = "https://api.sandbox.mangopay.com"
<% end %>
mangoPay.cardRegistration.clientId = 'inicat'
mangoPay.cardRegistration.init(cardInitData)
cardData =
cardNumber: $('#card_number').val()
cardExpirationDate: "#{$('#card_exp_month').val()}#{$('#card_exp_year').val()}" #Please note that the expiry date posted to the cardregistrationURL must be in this format: MMAA
cardCvx: $('#card_cvc').val()
cardType: 'CB_VISA_MASTERCARD'
# Register card
mangoPay.cardRegistration.registerCard cardData, ((response) ->
# Success, you can use response.CardId now that points to registered card
console.log response.CardId
console.log "success: #{response}"
return
), (response) ->
# Handle error, see response.ResultCode and response.ResultMessage
console.log "error: #{response.ResultCode}: #{response.ResultMessage}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment