BancBox REST API POST createClient - ruby-on-rails-3

I've spent the last day trying to get this to work in my Rails app, but continually get the response:
{"code"=>"E-C-343", "message"=>"Unrecognized JSON Request."}
BancBox's Documentation is pretty light, so I'm at a bit of an impasse on how to solve this.
Does anyone have an example of a successful API call to createClient at BancBox utilizing REST?
My Post API call utilizing HTTParty:
include HTTParty
format :json
def save_with_bancbox(params = {})
post_params = { :authentication => { :apiKey => BANCBOX_KEY,
:secret => BANCBOX_SECRET
},
:subscriberId => BANCBOX_ID,
:firstName => params[:first_name],
:lastName => params[:last_name],
:ssn => params[:ssn],
:dob => params[:dob],
:address => { :line1 => params[:address_line_1],
:line2 => params[:address_line_2],
:city => params[:city],
:state => params[:state],
:zipcode => params[:zipcode]
},
:homePhone => params[:dob],
:email => params[:email]
}
response = HTTParty.post( BANCBOX_REST_URL,
:body => post_params)
logger.debug "Response -- #{response}"
save!
end

Please try the below code after changing apikey, secret and subscriberid
require "net/https"
require 'rubygems'
require 'json'
require 'httparty'
###########################bancbox.rb in config/initializers#################
BANCBOX_API_KEY = "__KEY__"
BANCBOX_API_SECRET = "__SECRET__"
BANCBOX_SUBSCRIBER_ID = "__SUB_ID__"
BANCBOX_API_URL = "https://sandbox-api.bancbox.com/BBXPortRest"
module Bancbox
class API
include HTTParty
debug_output $stdout
base_uri "#{BANCBOX_API_URL}"
def initialize(u=BANCBOX_API_KEY,p=BANCBOX_API_SECRET)
auth = {:apiKey => u, :secret => p}
#options = {:body => {:authentication =>auth,:subscriberId=>BANCBOX_SUBSCRIBER_ID}, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' }}
end
#USERS
def create_client(options={})
options = options.merge(#options[:body])
#options.merge!({:body => options.to_json})
response = self.class.post("/createClient",#options)
#required_fields- subscriberId,firstName,lastName,ssn,dob,address,homePhone,email
end
def get_schedules(options={})
#options.merge!({:query => {:subscriberId => BANCBOX_SUBSCRIBER_ID}})
#options.merge!({:query => options})
self.class.post("/getSchedules",#options)
end
end
end
b = Bancbox::API .new
b.create_client({:firstName=> "Bipen",:lastName=> "Sasi",:ssn=>"334-444-4444",:dob=> Date.parse("January 1st 1988"), :address=>{:line1=> "4408 walnut st", :line2=>"apt 3r",:city=> "philly",:state=>"pa",:zipcode=>"19110"}, :homePhone=> "2672551161",:email=>"bipen#lokalty.com"})

I think you should POST the request to
https://sandbox-api.bancbox.com/BBXPortRest/createClient
instead of
https://sandbox-api.bancbox.com/BBXPortRest/
Also make sure to set the content type as application/json
In general, you post your request to https://sandbox-api.bancbox.com/BBXPortRest/<method>

Related

Rails 3 Overriding Devise Mailer

I am working on an app that is tightly being integrated in with Mandrill (MailChimp's transactional email service) and I am trying to override the Devise Mailer but for some reason when I send off the API call to Mandrill I receive their email, but Devise also sends me an email (which is blank).
Here is my DeviseMailer
class MyDeviseMailer < Devise::Mailer
def reset_password_instructions(record)
mandrill = Mandrill::API.new("#{MandrillConfig.api_key}")
mandrill.messages 'send-template',
{
:template_name => 'Forgot Password',
:template_content => "",
:message => {
:subject => "Forgot Password",
:from_email => "test#test123.com",
:from_name => "Company Support",
:to => [
{
:email => record.email
}
],
:global_merge_vars => [
{
:name => "FIRST_NAME",
:content => record.first_name
},
{
:name => "FORGOT_PASSWORD_URL",
:content => "<a href='#{edit_user_password_url(:reset_password_token => record.reset_password_token)}'>Change My Password</a>"
}
]
}
}
#We need to call super because Devise doesn't think we have sent any mail
super
end
end
The call to super I found here: http://qnundrum.com/answer.php?q=254917
I was running into a similar issue.
Did you update the devise initializer file (devise.rb) to specify the following:
config.mailer = "MyDeviseMailer"
You also needed to move any and all files in views/devise/mailer to views/mydevisemailer.
I would also restart your server.

Actionmailer Rails 3

I have added a contact form to my site and am having a problem, when the message is sent I get my flash message, "successfully sent", however the email never arrives in my inbox. I am in development mode at the moment and my app/config file looks like this
class Application < Rails::Application
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.raise_delivery_errors = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "myemail#gmail.com",
:password => "example",
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = {
:host => "gmail.com"
}
My contact Controller is like this
def new
#message = Message.new
end
def create
#message = Message.new(params[:message])
if #message.valid?
NotificationsMailer.new_message(#message).deliver
redirect_to(root_path, :notice => "Message was successfully sent.")
else
flash.now.alert = "Please fill all fields."
render :new
end
end
end
and finally my Notification Mailer
class NotificationsMailer < ActionMailer::Base
default :from => "myemail#gmail.com"
default :to => "myemail#gmail.com"
def new_message(message)
#message = message
if message.file
attachment_name = message.file.original_filename
attachments[attachment_name] = message.file.read
end
mail(:subject => "[myemail#gmail.com] #{message.subject}")
end
end
Am I missing anything obvious here as I have implemented this in another site which worked fine, just cant figure out what is going on
Any help appreciated
I know you set it in your app/config.rb, but I would ensure config.action_mailer.perform_deliveries isn't being overridden in your config/environments/development.rb

Netzke basepack. Need advice with multi uploading fields

Is there any easy way to include the multiupload feature to NetzkeFormView or GridView(AddInForm)?
My current image uloading field with carrierwave is:
{:name => :image_link, :xtype => :displayfield, :display_only => true, :getter => lambda { |r| %Q(<a href='#{r.image.url}'>Download</a>) if r.image.url }},
{:name => :image, :field_label => "Upload image", :xtype => :fileuploadfield, :getter => lambda { |r| "" }, :display_only => true}

Rails3 ActionMailer deliveries in development environment

Is it possible to send mailers in the development environment?
I've added this to my development.rb file:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
:address => "mail.email.com",
:port => 25,
:domain => 'email.com',
:user_name => 'email#email.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true }
Then I run UserMailer.welcome_email(#user).deliver in rails console which returns #<Mail::Message:2265713480, Multipart: true, Headers: <Date: Thu... but I never actually receive the email. Is there something else I need to configure?
Oh, and if I check ActionMailer::Base.deliveries it returns an empty hash => [].
Needed to add the following to environments/development.rb:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true

Submit PayPal data encrypted from the code

I'm working with Ruby On Rails 3, and I would like to do the following, but from the code behind:
<% form_tag "https://www.sandbox.paypal.com/cgi-bin/webscr" do %>
<%= hidden_field_tag :cmd, "_s-xclick" %>
<%= hidden_field_tag :encrypted, #cart.paypal_encrypted(products_url, payment_notifications_url) %>
<p><%= submit_tag "Checkout" %></p>
<% end %>
I've tried this in my Cart model, but it's not redirecting anywhere, and I don't know what to do:
PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")
PANEL = 'sandbox.paypal.com'
PATH = '/cgi-bin/webscr'
USERAGENT = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1'
def paypal_url(order_id, return_url, notify_url)
http = Net::HTTP.new(PANEL, 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
# GET request -> so the host can set cookies
resp, data = http.get2(PATH, {'User-Agent' => USERAGENT})
cookie = resp.response['set-cookie'].split('; ')[0]
values = {
:cmd => '_s-xclick',
:encrypted => paypal_encrypted(order_id, return_url, notify_url)
}
#headers = {
'Cookie' => cookie,
'Referer' => 'https://'+PANEL+PATH,
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => USERAGENT
}
resp, data = http.post2(PATH, values.to_query, #headers)
end
def paypal_encrypted(order_id, return_url, notify_url)
values = {
:business => 'seller_1234111143_biz#asciicasts.com',
:cmd => '_cart',
:upload => 1,
:return => return_url,
:invoice => order_id.to_s,
:notify_url => notify_url,
:currency_code => "USD"
}
items.each_with_index do |item, index|
values.merge!({
"amount_#{index + 1}" => item.unit_price,
"item_name_#{index + 1}" => item.product.title,
"item_number_#{index + 1}" => item.product.id + Time.now.to_i,
"quantity_#{index + 1}" => item.quantity.to_i
})
end
encrypt_for_paypal(values)
end
def encrypt_for_paypal(values)
signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end
If you're wondering why I can't just use the html form, that's because I let users choose between more than one payment option, using radio fields, and once they have selected one, they will click on the "Submit Order" button, generating the respective movements in my database, before redirecting to the payment method.