ActiveMerchant requiring pin? - ruby-on-rails

I am using activemerchant in a rails application like this
ActiveMerchant::Billing::Base.mode = :test
::GATEWAY = ActiveMerchant::Billing::UsaEpayGateway.new(
:login => "SOMEKEY"
)
and I keep getting this error code
error_code: \"10117\"\nauth_code: \"000000\"\nstatus: Error\nerror: Transaction authentication required.\n
when i look at the error codes (10117) for usaepay I notice that i need to enter in the pin. This I have, but i dont know how to implement. I tried these two below
ActiveMerchant::Billing::Base.mode = :test
::GATEWAY = ActiveMerchant::Billing::UsaEpayGateway.new(
:login => "SOMEKEY",
:password => "MYPIN"
)
ActiveMerchant::Billing::Base.mode = :test
::GATEWAY = ActiveMerchant::Billing::UsaEpayGateway.new(
:login => "SOMEKEY",
:pin => "MYPIN"
)
and I still get the same error
Looking at the USAEPAY Library's initializer I see login but not pin
def initialize(options = {})
requires!(options, :login)
#options = options
super
end
...any ideas how I can sent this pin into Activemerchant
UPDATE
here is my call to the transaction
options = {
:card_code=>self.card_verification
:billing_address=>{
:address1=>self.billing_address,
:city=>self.city,
:state=>self.state,
:zip=>self.zip,
:country=>"US"
}
}
response = GATEWAY.purchase(price_in_cents, credit_card, options)
i tried to do this
options = {
:card_code=>self.card_verification,
:pin=>"333333",
:billing_address=>{
:address1=>self.billing_address,
:city=>self.city,
:state=>self.state,
:zip=>self.zip,
:country=>"US"
}
}
response = GATEWAY.purchase(price_in_cents, credit_card, options)
but still nothing

Maybe you need to pass the authorization pin into the transaction. Can you paste the code where you call a transaction, please?
For example, calling this method: capture(money, authorization, options = {})
Edit:
I don't think ActiveMerchant has the pin feature implemented. Here are your options:
Use another script. Here are some examples: http://wiki.usaepay.com/developer/ruby
Add this to your Gemfile: gem 'activemerchant', :git => 'git://github.com/kalinchuk/active_merchant.git' It will install a gem from my github account. I added the pin field to active merchant.
You can then call:
::GATEWAY = ActiveMerchant::Billing::UsaEpayGateway.new(
:login => "SOMEKEY",
:pin => "PIN"
)

Related

Uninitialized constant ActiveMerchant

In rails i'm getting the error uninitialized constant CartController::EXPRESS_CHECKOUT while i'm calling the method express_checkout of the controller CartController, i think that the problem is in config/environments/development.rb file, because i defined
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
login: "<mail>",
password: "<pass>",
signature: "<sig>"
}
::EXPRESS_GATEWAY =
ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
end
But even if i tried to change something in this file, i can't fix this error.
This is the code of cart_controller.rb
def express_checkout
response = EXPRESS_GATEWAY.setup_purchase(params[:amount], ip: request.remote_ip, return_url: "http://localhost:8080/checkout_details", cancel_return_url: "http://localhost:8080", currency: "EUR", allow_guest_checkout: true, items: [{name: "Order", description: "Order description", quantity: "1", amount: params[:amount]}]
)
redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
end
def checkout_details
#token = params[:token]
#payer_id = params[:PayerID]
#details = EXPRESS_GATEWAY.details_for(#token)
end
def purchase
#t = params[:token]
#p = params[:PayerID]
#result = EXPRESS_GATEWAY.purchase(params[:amount], {:token => #t, :payer_id => #p, :currency => "EUR"})
end
I checked the version of the gem activemerchant and is version 1.66.0, so the version of this gem is not a problem.
Anyone knows something about this?
As Tobias suggested me, i corrected the mistake in CartController.rb, modifying EXPRESS_GATEWAY in ::EXPRESS_GATEWAY. After this change, i restarted the rails server and everything works perfectly!

Save Contact ID From Sales Force Response Into Users Table Databasedotcom

***** 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)

undefined method `values_at' for nil:NilClass when I use WashOut gem

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.

Savon: user not authorized

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).

Constantly get Authentication+failed.+API+credentials+are+incorrect

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

Resources