I am using savon gem for accessing abc financial web services. I am getting error message user not authorize. I am using this code for accessing response
#wsdl="https://webservice.abcfinancial.com/wsdl/Prospect.wsdl"
#basic_auth=["user","pass"]
#headers={"Authorization" => "Basic"}
#client = Savon.client do |globals|
globals.wsdl #wsdl
globals.basic_auth #basic_auth
globals.headers #headers
end
#message = {
:clubNumber=> 'Club 0233',
:firstName=> 'abc',
:lastName=> 'def',
:gender=> "male"
}
response = #client.call(:insert_prospect, message: #message)
and I am getting an error message user not authorize. I searched it but didn't find any solution. Please help me.
They are using JAX-WS.
According to this article http://examples.javacodegeeks.com/enterprise-java/jws/application-authentication-with-jax-ws/ (and google) we should use login-password in http headers.
I don't have an account on the http://abcfinancial.com so I can't test the code.
Try it:
require 'savon'
user = 'myLogin'
password = 'myPassword'
client = Savon.client(
wsdl: 'https://webservice.abcfinancial.com/wsdl/Prospect.wsdl',
headers: {username: user,
password: password},
pretty_print_xml: true,
log: true
)
message = {
:arg0 => {
clubNumber: 'Club 0233',
:personal => {
:firstName => 'myName',
:lastName => 'myLastName',
:gender => 'male'
}
}
}
response = client.call(:insert_prospect, message: message)
Read this good article http://predic8.com/wsdl-reading.htm and turn on debugging (pretty_print_xml: true, log: true).
Related
I am new to Mandrill so this may be the root cause of my issue :) - I have it working from this example:
https://nvisium.com/blog/2014/10/08/mandrill-devise-and-mailchimp-templates/
I don't think it's a Devise issue but I figured I would mention it. Here is my DeviseMailer code:
def invitation_instructions(record, token, opts={})
options = {
:subject => "Subject",
:from_name=> "From",
:email => record.email,
:global_merge_vars => [
{ name: 'invite_name', content: "Invited By" },
{ name: 'invite_email', content: "Invited By Email" },
{ name: 'invite_company', content: "Company Name" },
{ name: 'invitation_url', content: root_url(:invitation_token => token) } #accept_invitation_url(record, :invitation_token => token)
],
:template => "Invitation",
:template_name => "Invitation"
}
mandrill_send options
#MandrillEmail.perform_async(options)
end
def mandrill_send(opts={})
message = {
:subject=> "#{opts[:subject]}",
:from_name=> "#{opts[:from_name]}",
:from_email=>"do-not-reply#xxxxx.com",
:to=>
[{"email"=>"#{opts[:email]}",
"type"=>"to"}],
:global_merge_vars => opts[:global_merge_vars]
}
sending = MANDRILL.messages.send_template opts[:template], [], message
rescue Mandrill::Error => e
Rails.logger.debug("#{e.class}: #{e.message}")
raise
end
This works - I get my email and the templates work etc.
Now if I move the logic to a SideKiq worker (MandrillEmail.perform_async(options)) it fails with:
Mandrill::ValidationError: Validation error: {"template_name":"Sorry, this field can't be left blank.","message":{"to":[{"email":"Sorry, this field can't be left blank."}]}}
I added :template_name => "Invitation" but that doesn't work. My sidekiq monitor clearly shows both the template_name and message>to>email: params being passed into the worker.
Not sure what I am missing here.
Likely you are running into a string/symbol conflict. Symbols cannot be passed to Sidekiq jobs.
https://github.com/mperham/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple
I try to logon Affili.net via SOAP by using the savon-gem.
client = Savon.client do
wsdl "https://api.affili.net/V2.0/Logon.svc?wsdl"
end
message = {
'Username' => '123123',
'Password' => '123123',
'ins2:WebServiceType' => 'Publisher' }
response = client.call(:logon, :message => message)
But I only get this exception:
(a:DeserializationFailed) The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://affilinet.framework.webservices/Svc:LogonRequestMsg. The InnerException message was 'Error in line 1 position 777. 'EndElement' 'LogonRequestMsg' from namespace 'http://affilinet.framework.webservices/Svc' is not expected. Expecting element 'Username | Password | WebServiceType'.'. Please see InnerException for more details.
https://developer-api.affili.net/V2.0/Logon.svc?wsdl
Whats wrong?
Update
Now i tried some tools like this:
http://www.soapclient.com/soapclient?template=%2Fclientform.html&fn=soapform&SoapTemplate=%2FSoapResult.html&SoapWSDL=https%3A%2F%2Fdeveloper-api.affili.net%2FV2.0%2FLogon.svc%3Fwsdl&_ArraySize=2
And it also tells me: it does not work. But my Account and that credentials are ok!
So I tried it on PHP
define ("WSDL_LOGON", "https://api.affili.net/V2.0/Logon.svc?wsdl");
define ("WSDL_STATS", "https://api.affili.net/V2.0/PublisherStatistics.svc?wsdl");
$Username = '123123'; // the publisher ID
$Password = '123123'; // the publisher web services password
$SOAP_LOGON = new SoapClient(WSDL_LOGON);
$Token = $SOAP_LOGON->Logon(array(
'Username' => $Username,
'Password' => $Password,
'WebServiceType' => 'Publisher'
));
echo $Token;
and it works!
Whats the difference between all online tools, all offline tools and Ruby on Rails and PHP?
Try to send message with symbolized keys, like this:
message = {
logon: {
username: '123123',
password: '123123',
web_service_type: 'Publisher'
}
}
I still do not know the difference between the savon (2.7.2) and the PHP implementation.
But there is a solution for affili.net by using savon 3 (but it is not stable yet!)
client = Savon.new("https://api.affili.net/V2.0/Logon.svc?wsdl")
logon_body = {
LogonRequestMsg: {
'Username' => '123123',
'Password' => '123123',
'WebServiceType' => 'Publisher'
}
}
operation = client.operation('Authentication', 'DefaultEndpointLogon', 'Logon')
operation.body = logon_body
response = operation.call
puts response.body[:credential_token]
Some Savon 3 Documentation: http://savonrb.com/version3/getting-started.html
And the github branch: https://github.com/savonrb/savon/tree/version3
***** RESPONSE: Net::HTTPOK -> {"status":"Success","primary_language":"notsure","PortalID":"1017","newContact":{"attributes":{"type":"Contact","url":"/services/data/v31.0/sobjects/Contact/003f000000goEpIAAU"},"Primary_Language_Master__c":"notsure","npe01__Preferred_Email__c":"Personal","Country_of_Birth_Master__c":"argentina","npe01__HomeEmail__c":"john.smith1228+689#gmail.com","RecordTypeId":"012i0000000Ng8uAAC","Portal_ID__c":1017,"FirstName":"John","Id":"003f000000goEpIAAU","LastName":"Smith", "High_School_Graduation_Year__c":"2007"},"message":"Create was created successfully.","lastname":"Smith","high_school_graduation_year":2007,"firstname":"John","email":"john.smith1228+689#gmail.com","country_of_residence":"argentina","ContactID":"003f000000goEpIAAU"}
The above is a response getting returned after I use the databasedotcom gem to interact with salesforce. I am trying to collect the contactid into my users table after a successfuly response.
Below is the method that I am pushing with
def salesforce_add_contact
client = Databasedotcom::Client.new("config/databasedotcom.yml")
client.authenticate(:username => "secret", :password => "secret" )
params = { :PortalID => current_user.id.to_s,
:firstname => current_user.first_name,
:lastname => current_user.last_name,
:email => current_user.email,
:country_of_residence => current_user.country_of_residence,
:primary_language => current_user.primary_language,
:high_school_graduation_year => current_user.high_school_graduation_year}
params = ActiveSupport::JSON.encode(params)
path = "/services/apexrest/v2/portalAccount"
result = client.http_post(path, params)
result = ActiveSupport::JSON.decode(result.body)
puts result.body #just added
if (response['status'] == "Success") #this didn't work
current_user.sfdc_contact_id = response['ContactId']
current_user.sfdc_contact_id.save
end
end
I am not totally understanding the syntax from the response and what kind of data structure is getting returned either....
I am trying to collect this "ContactID":"003f000000goEpIAAU"
Updated
I am getting NoMethodError (undefined methodbody' for #):`
when I do a puts result.body so I guess its not reading it correctly.
It looks you misnamed the variable that contains the decoded JSON response. You have:
result = ActiveSupport::JSON.decode(result.body)
Which should be:
response = ActiveSupport::JSON.decode(result.body)
I'm writing a test for Facebook integration. When I run rspec, I get the following error
Failure/Error: before { click_link "Sign in with Facebook" }
NoMethodError:
undefined method `provider' for #<Hash:0x007fbe98511798>
# ./app/models/user.rb:55:in `from_omniauth'
My OAuth mock contains
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:facebook] = {
'uid' => "999999",
'provider' => "facebook",
'extra' => {
'user_hash' => {
'email' => 'test#gmail.com',
'first_name' => 'First',
'last_name' => 'Last',
'gender' => 'Male'
}
},
'credentials' => {
'token' => "token1234qwert"
}
}
The exact place it apparently breaks is
def self.from_omniauth(auth)
where("fb_provider = ? and fb_uid = ?", auth.provider, auth.uid.to_s).first_or_initialize.tap do |user|
But when I do a puts auth.to_yaml as the first line in from_omniauth(auth) it shows provider: facebook along with everything else I included in my mock auth. I'm lost at this point. Any suggestions or help would be appreciated. Thanks.
Your code should be this:
where("fb_provider = ? and fb_uid = ?", auth['provider'], auth['uid'].to_s ...
This is because auth in this instance is a Hash object and Hash objects do not respond to methods by the same name as their keys. Instead, you should just use the Hash#[] method -- as I've demonstrated -- to access the value for those keys.
I'm trying to create simple PayPal Pay API operation, when I run this code from console it gave me response, that payment is created.
Now, when I'm tring to run it from my controller it gives me
Authentication+failed.+API+credentials+are+incorrect.
Here is my controller :
def pay
require 'httpclient'
require 'xmlsimple'
clnt = HTTPClient.new
credentials = {
'USER' => 'payer_1342623102_biz_api1.gmail.com',
'PWD' => '1342623141',
'SIGNATURE' => 'Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL '
}
header = {"X-PAYPAL-SECURITY-USERID" => "payer_1342623102_biz_api1.gmail.com",
"X-PAYPAL-SECURITY-PASSWORD" => "1342623141",
"X-PAYPAL-SECURITY-SIGNATURE" => "Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL ",
"X-PAYPAL-REQUEST-DATA-FORMAT" => "NV",
"X-PAYPAL-RESPONSE-DATA-FORMAT" => "XML",
"X-PAYPAL-APPLICATION-ID" => "APP-80W284485P519543T"
}
data = {"actionType" => "PAY",
"receiverList.receiver(0).email"=> "denmed_1342605975_biz#gmail.com",
"receiverList.receiver(0).amount" => "10",
"currencyCode" => "USD",
"cancelUrl" => "http://127.0.0.1:3000",
"returnUrl" => "http://127.0.0.1:3000",
"requestEnvelope.errorLanguage" => "en_US"}
uri = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay"
res = clnt.post(uri, data, header)
#xml = XmlSimple.xml_in(res.content)
payKey = #xml["payKey"].to_s()
payKey = payKey.tr("[]", "")
payKey = payKey[1..20]
redirect_to "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay?cmd=_ap-payment&paykey=#{payKey}"
end
Is everything ok ? Can anyone suggest reason my request fails ?
One good man found my error. I redirect user to the wrong url.
This line:
redirect_to "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay?cmd=_ap-payment&paykey=#{payKey}"
Should be:
redirect_to "https://sandbox.paypal.com/webscr?cmd=_ap-payment&paykey=#{paykey}"
I got the same error: I realized I forgot to include
sandbox_email_address: xxx#example.com
in my yml file