Closed mgharbik closed 10 years ago
Why are you using Net::HTTP instead of MangoPay::CardRegistration class ?
We have the same problem when updating the cardRegistration object, but we don't get 500, we get an exception saying, well not much :(
_registrationdata is mu7wHX5Ed2CEyB4bywAkOXtttYH5Y3AgUF0e5nsibxwyyWcm__7razpSbVHEIU0krjoz4XjJxTKhkivQDXr0b5AICZyRLextnpJqDtFtFfOCZcKaHHf0_VVtmrh7ipOKnnH2fgUNSagxQdH6YLy6_XLIHP71orBPaAfyhvGW1wVPNVwpgWD3oasOY0WK96UH8Kpf4UFZHLwk7FKxJKftQs
def self.update_card_registration(registration_data) begin response = MangoPay::CardRegistration.update({ RegistrationData: "data="+registration_data }) return response rescue => e # rescue => e is shorthand for rescue StandardError => e Rails.logger.error "e.inspect: #{e.inspect}\n Arguments were #{registration_data}" Rails.logger.error e.message e.backtrace.each { |line| Rails.logger.error line } return false end end
The output is:
e.inspect: #
and the stack output is: /.rvm/gems/ruby-2.0.0-p353@rent-it-all/gems/mangopay-3.0.9/lib/mangopay.rb:97:in `request'
/.rvm/gems/ruby-2.0.0-p353@rent-it-all/gems/mangopay-3.0.9/lib/mangopay/http_calls.rb:20:in `update'
/rent-it-all/app/models/mango_card_registration.rb:48:in `update_card_registration'
/rent-it-all/app/controllers/payments_controller.rb:25:in `index'
Hi Luka,
I think you're missing the card id while calling the update method, you should do something like: MangoPay::CardRegistration.update( card_id_here, { RegistrationData: "data="+registration_data })
Moreover, I see that your registration data is too long, my problem was this. I also believe that the payment service provider returns the string including data= so you don't have to append it.
I hope that helps,
Thanks for the reply! I don't have the card_id at this moment. The card_id should be the result of the UPDATE call. What I have from the CREATE call is: { "Id"=>"2384078", "Tag"=>"", "CreationDate"=>1400606439, "UserId"=>"2049049", "AccessKey"=>"1X0m87dmM2LiwFgxPLBJ", "PreregistrationData"=>"HBalUf7sKsj1NiktfVS7-5PWGitCdM8Ja4L2AuqkJbi0m00w9YnVX01uitACAo9KS4wCy-yiraxeE65tmxOe8A", "RegistrationData"=>nil, "CardId"=>nil, "CardType"=>"CB_VISA_MASTERCARD", "CardRegistrationURL"=>"https://homologation-webpayment.payline.com/webpayment/getToken", "ResultCode"=>nil, "ResultMessage"=>nil, "Currency"=>"EUR", "Status"=>"CREATED" }
Then I build the users form with hidden fields holding:
User's browser is then redirected to returnUrl where we get as a URL parameter data=XYXYXYXYX
Now we are supposed to update the cardRegistration object by calling
MangoPay::CardRegistration.update({ RegistrationData: "data="+registration_data })
Now, you mentioned that I should also send an ID which I guess is not the CardId because it's nil, but the "Id"=>"2384078"
Mango documentation doesn't even mention that ID: http://docs.mangopay.com/api-references/card-registration/ in the 5. section... Weird...
Ok, I'll try the following:
MangoPay::CardRegistration.update({
Id: "2384078"
RegistrationData: "data="+registration_data
})
Thanks for the hint !!!
Solved it! Thanks Simo... Your hint with cardId helped a lot... Event hough documentation never mentioned it the update call should contain card_registration_id (not Card ID but the Id returned from cardregistration create request)
MangoPay::CardRegistration.update( card_registration_id, { RegistrationData: "data=#{registration_data}" })
How do you pass around the card_registration_id? Well I send it in the form redirect URL, but it should be saved in the users session
Thanks a lot! Luka
Hi Luka, I am glad that worked!
When you update the RegistrationData field is actually step 8 (not step 5). Moreover, I think the documentation is fine, take a look in the PUT tab they mention the id by URL: /CardRegistrations/{id}
Back to step 5, this step consists in sending a post http request to the CardRegistrationURL passing the credit card information such as above in my first post (data, accessKeyRef, returnURL, cardNumber", cardExpirationDate, cardCvx).
In terms of your question, it is up to you how you'd implement the flow. If I were you, I would do the whole process in just one action.
My bests,
Sorry I meant point 5 in EDIT tab of http://docs.mangopay.com/api-references/card-registration/ URL: /CardRegistrations/{id} It says in the example: { "RegistrationData" : "data=gcpSOxwNHZutpFWmFCAYQu1kk25qPfJFdPaHT9kM3gKumDF3GeqSw8f-k8nh-s5OC3GNnhGoFONuAyg1RZQW6rVXooQ_ysKsz09HxQFEJfb-6H4zbY2Nnp1TliwkEFi4" } so, no client_id there :( I know what you mean... PUT /CardRegistrations/{id} in RESTful means exactly that, but I am using a Ruby SDK which wraps everything up in methods so I had no idea how to pass that ID...
I am done... This was the only obstacle... Basically everything is done M2M in one go so user has no idea that behind the scenes we are communicating and redirecting his browser around :D
Thank you so much...
@luigi7up Could you please share your full solution for Registering a card ?
Hi all, We are trying to register a card before doing a Payin following the Direct payin flow http://docs.mangopay.com/api-references/payins/payindirectcard/, but while updating the card (step 8) it answers the 500 Internal Server Error.
To post the card data I am using: params["data"] = json_card_object['PreregistrationData'] params["accessKeyRef"] = json_card_object['AccessKey'] params["cardNumber"] = "4970101122334430" params["cardExpirationDate"] = "0315" params["cardCvx"] = "123" result = Net::HTTP.post_form(URI.parse(json_card_object['CardRegistrationURL']), params) result.body
The RegistrationData string I receive is more longer than the one in Mangopay API, something like: data=WVmFSAUMn-G6mA8DT5RRhGeRyY2yVuBgw35ZuzCjcxxB6BXS8H3k6V9HTbWla5lPiuBaSeE_b720KH7WK_tBxHU_8uD3dhc4BnvNy6DBw5vGS2KXo6R6k6ACMqjD3a5f0ftfDdcAJsF-g-uibptl8--K13F9Jp8hQmf7PQ0qzTNuUPt1a9byNy78ZDAK-xIfnCXaSHcj3rsvcqvu89itONv0HWr75RRP2g1tAEHKkbjpheN213zUctdzvpRQyeRD
Could anybody please tell us how to solve this issue! Thanks!
With kind regards,