***** 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)
Related
This gem sends data to Amazon. However, its missing one data element that I need to send. Basically the declared value of the item. I am trying to monkey patch this method to also send the declared value.
The method I'm using inside this gem is create_fulfillment_order here is a link to the method, and the method is also pasted below. What I need to do is change the items struct from this:
(:seller_sku, :seller_fulfillment_order_item_id, :quantity)
to this:
(:seller_sku, :seller_fulfillment_order_item_id, :quantity, :per_unit_declared_value)
And then this is the complete code for the method
def create_fulfillment_order(seller_fulfillment_order_id, displayable_order_id, displayable_order_date_time, displayable_order_comment, shipping_speed_category, destination_address, items, opts = {})
if opts.key?(:cod_settings)
opts['CODSettings'] = opts.delete(:cod_settings)
end
operation('CreateFulfillmentOrder')
.add(
opts.merge(
'SellerFulfillmentOrderId' => seller_fulfillment_order_id,
'DisplayableOrderId' => displayable_order_id,
'DisplayableOrderDateTime' => displayable_order_date_time,
'DisplayableOrderComment' => displayable_order_comment,
'ShippingSpeedCategory' => shipping_speed_category,
'DestinationAddress' => destination_address,
'Items' => items
)
)
.structure!('Items', 'member')
.structure!('NotificationEmailList', 'member')
run
end
I call the method like this:
client = MWS::FulfillmentOutboundShipment::Client.new(
marketplace_id: "XXXXXX",
merchant_id: "XXXXX",
aws_access_key_id: "XXXX",
aws_secret_access_key: "XXXXX+",
auth_token: "XXXXXX")
Address = Struct.new(:name, :line_1, :line_2, :line_3, :city, :state_or_province_code,
:country_code, :postal_code)
address = Address.new("Todd T", "19712 50th Ave W", "#5", "", "Lynnwood","WA" ,"US" , "98036" )
Value = Struct.new(:currency_code, :value)
value = Value.new("CAD", "10")
Item = Struct.new(:seller_sku, :seller_fulfillment_order_item_id, :quantity, :per_unit_declard_value)
sku = []
first = Item.new("636391317719", "s2", 1, value)
sku << first
begin
client.create_fulfillment_order("z536", "z536", Time.now.getutc, "Thank You", "Standard", address, sku)
rescue Exception => e
pp e.response
end
The error I'm getting is The request must contain the parameter PerUnitDeclaredValue.
I am new to WSDL.
Code (I have added in the view directly - for test): (Page: http://localhost:3000/ccapis )
require 'savon'
client = Savon::Client.new(wsdl: "http://localhost:3000/ccapis/wsdl")
result = client.call(:fetch_prizes, message: { :gl_id => "123456789" })
result.to_hash
And in the controller:
soap_action "fetch_prizes",
:args => { :gl_id => :string },
:return => [:array]
def fetch_prizes
glnumber = params[:gl_id ]
prize = Prize.where(:gl_id => glnumber)
prize_to_show = []
a_hash = {}
prize.each do |p|
a_hash = { :prize => p.prize.to_s, :score => p.score.to_s, :date => p.round_date.to_s }
prize_to_show.push a_hash
a_hash = nil
end
render :soap => prize_to_show
end
When I try and run this in the Console all are good and I can see the result.to_hash but when I go to http://0.0.0.0:3000/ccapis I get the error that I mentioned above.
Explanation of what I am trying to achieve:
I need to supply a WSDL for a client which fetches all the prizes based on a score.
If My approach is wrong please direct me to a document so I can have a read and get a better understanding. Thanks again.
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).
I think I stated the title of this question right, but this is the issue:
I have the following in my SurveysController-
def pull_responses
call= "/api/v2/surveys/"
auth = {:username => "test", :password => "password"}
url = HTTParty.get("https://fluidsurveys.com#{call}",
:basic_auth => auth,
:headers => { 'ContentType' => 'application/json' } )
response = JSON.parse(url.body)
survey_ids = response["surveys"].map { |s| s["id"] }
survey_ids.each do |x|
call= "/api/v2/surveys/#{x}/responses/?_completed=1"
auth = {:username => "test", :password => "password"}
url = HTTParty.get("https://Fluidsurveys.com#{call}",
:basic_auth => auth,
:headers => { 'ContentType' => 'application/json' } )
response = JSON.parse(url.body)
response_count = response["count"]
Survey.create(y: response_count)
end
end
helper_method :pull_responses
All I am trying to do is put the variable response_count in my Surveys view. I may not need Survey.create(y: response_count), but that was a peice of one of my attempts to get this to work. Essentially, I just want to write this in a view:
puts response_count
What is the proper way to put that response into a view?
You need to assign the value to an instance variable (by adding # before the name) so that it will persist to the view:
#response_count = response["count"]
then in the view you can print it like so:
<%= #response_count %>
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