undefined method `[]' for false:FalseClass on adaptivepayments-sdk-ruby - ruby-on-rails

Someone is having this issue? or now why this is happing on configuring the paypal sdk adaptive?
place the configuration on the yml did not show this message but did not work either, so
i place the sdk configure on: buy action
and on the log shows:
line 58 is PayPal::SDK.configure
NoMethodError (undefined method []' for false:FalseClass):
app/controllers/orders_controller.rb:58:inbuy'
def buy
require 'paypal-sdk-adaptivepayments'
PayPal::SDK.configure(
:mode => "live", # Set "live" for production
:app_id => "APP-xxxxx",
:username => "xxxx.yyyy.com",
:password => "xxxx",
:signature => "xxxxx" )
#api = PayPal::SDK::AdaptivePayments.new
order = Order.find(params[:id])
#pay = #api.build_pay({
:actionType => "PAY",
:cancelUrl => carts_url,
:currencyCode => "US",
:feesPayer => "SENDER",
:ipnNotificationUrl => ipn_notification_order_url(order),
:receiverList => {
:receiver => [{
:email => seller#seller.com,
:amount => 1.0,
:primary => true},
{:email => buyer#buyer.com,
:amount => 1.0,
:primary => false}]},
:returnUrl => carts_url })
#response = #api.pay(#pay)
# Access response
if #response.success? && #response.payment_exec_status != "ERROR"
#response.payKey
redirect_to #api.payment_url(#response) # Url to complete payment
else
#response.error[0].message
redirect_to fail_order_path(order)
end
end

Related

API POST with array using HTTP gem (or RestClient)

I'm having trouble with this api and can't seem to get over the hump. Using the HTTP gem (though I'm flexible and can use RestClient if that gets me an answer quicker!). Anyway, I'm having trouble posting an array. everything else is good, I just can't figure out this "itemsarray" in the printaura api found here in the addorder method: PrintAura API
I'm running this:
def self.submitorder
req = HTTP.post("https://api.printaura.com/api.php", :json => {
:key => APIKEY,
:hash => APIHASH,
:method => "addorder",
:businessname => "this is a secret too",
:businesscontact => "thats a secret",
:email => "my#email.com",
:your_order_id => "1",
:returnlabel => "FakeAddress",
:clientname => "ShippingName",
:address1 => "ShippingAddressLine1",
:address2 => "ShippingAddressLine2",
:city => "ShippingCity",
:state => "ShippingState",
:zip => "ShippingZip",
:country => "US",
:customerphone => "dontcallme",
:shipping_id => "1",
:itemsarray => {:item => [
:product_id => 423,
:brand_id => 33,
:color_id => 498,
:size_id => 4,
:front_print => 1389517,
:front_mockup => 1390615,
:quantity => 1
]}
})
puts JSON.parse(req)
end
And my output is this:
{"status"=>false, "error_code"=>19, "result"=>19, "message"=>"You cannot place an order without items, Please fill the items array with all the required information. Full API documentation can be found at https:/www.printaura.com/api/"}
Gosh, if someone could look at that and help me out I would forever appreciate it.
def self.submitorder
itemsarray = { :items => [ { :product_id => 423, :brand_id => 33, :color_id => 498, :size_id => 4, :quantity => 1, :front_print => 1389517,
:front_mockup => 1390617 } ] }
req = HTTP.post("https://api.printaura.com/api.php", :json => {
:key => APIKEY,
:hash => APIHASH,
:method => "addorder",
:businessname => "this is a secret too",
:businesscontact => "thats a secret",
:email => "my#email.com",
:your_order_id => "1",
:returnlabel => "FakeAddress",
:clientname => "ShippingName",
:address1 => "ShippingAddressLine1",
:address2 => "ShippingAddressLine2",
:city => "ShippingCity",
:state => "ShippingState",
:zip => "ShippingZip",
:country => "US",
:customerphone => "dontcallme",
:shipping_id => "1",
:items => Base64.encode64(itemsarray.to_json)}
)
puts JSON.parse(req)
I really hopes this helps somebody some years from now haha
To create a array in JSON you use an array in Ruby. Its that easy.
require 'json'
def self.submitorder
req = HTTP.post("https://api.printaura.com/api.php", :json => {
:key => APIKEY,
:hash => APIHASH,
:method => "addorder",
:businessname => "this is a secret too",
:businesscontact => "thats a secret",
:email => "my#email.com",
:your_order_id => "1",
:returnlabel => "FakeAddress",
:clientname => "ShippingName",
:address1 => "ShippingAddressLine1",
:address2 => "ShippingAddressLine2",
:city => "ShippingCity",
:state => "ShippingState",
:zip => "ShippingZip",
:country => "US",
:customerphone => "dontcallme",
:shipping_id => "1",
:items => [
{
:product_id => 423,
:brand_id => 33,
:color_id => 498,
:size_id => 4,
:front_print => 1389517,
:front_mockup => 1390615,
:quantity => 1
}
]
})
puts JSON.parse(req)
The API lists a items parameter which should contain an array of objects. It says nothing about itemsarray.

how to do ccavenuee payment gateway integration in rails

I tried ccavenue but I'am getting this error. paypal is working fine.
undefined methodpayment_service_for'`
This is my controller action
def create
#subscription = Subscription.new(subscription_params)
#programme = Programme.find(subscription_params[:programme_id])
rand_number = rand.to_s[2..11]
#programme.update_attributes(:invoice_id => rand_number)
session[:programme_id]=#programme.id
session[:invoice_id]=#programme.invoice_id
#paypal = PaypalPayment.create(:material_type => 'Programmes',:invoice_id => rand_number,:currency => #programme.currency, :status => 'Processing', :created_at => DateTime.now, :user_id => current_user.specific.id, :email_id => current_user.specific.email, :programme_id => #programme.id,:amount => #programme.price_paisas)
#paypal.save
`session[:paypal_id]=#paypal.id
logger.info #programme.inspect
if subscription_params[:payment_type] == 'paypal'
item_details=[]
if #programme.currency == 'INR'
price = #programme.price.exchange_to('USD')
else
price = #programme.price
end
logger.info price.inspect
item_details << {:name => #programme.title, :quantity => '1', :amount => price.fractional}
response = EXPRESS_GATEWAY.setup_purchase(price.fractional,
:items => item_details,
:currency => "USD",
:order_id => #programme.invoice_id,
:return_url => students_success_url,
:cancel_return_url => students_root_url
)
logger.info response.inspect
session[:programme_price]=price
return redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
elsif subscription_params[:payment_type] == 'ccavenue'
payment_service_for #programme.invoice_id, CCAVENUE_ACCOUNT,
:amount => #programme.price.fractional,
:currency => 'INR',
:service => :ccavenue do |service|
service.customer :name => current_user.name,
:email => current_user.email,
:phone => current_user.mobile
service.redirect :return_url => students_success_url
submit_tag 'Proceed to payment'
end
end
end
end`
I referred this link:
https://github.com/meshbrain/active_merchant_ccavenue
The payment_service_for is the view helper of the Active Merchant gem. You should use this method inside views or you should include view helpers inside your controller.

How to get the country and state from a paypal transaction?

I would like to know how to obtain the country and state, from the billing address, in a paypal transaction.
So far I can get a transaction object via the code below:
# ...
def self.paypal_transaction_details(txn_id)
#api = PayPal::SDK::Merchant.new
get_transaction_details = #api.build_get_transaction_details({:TransactionID => txn_id })
response = #api.get_transaction_details(get_transaction_details)
end
Is it possible to get the location info? Or should I use geocoder to get the country and state from the ip address?
Reference: https://github.com/paypal/merchant-sdk-ruby
Response:
response.PaymentTransactionDetails.PayerInfo.Address
=> #<PayPal::SDK::Merchant::DataTypes::AddressType:0x007fd58f604660 #AddressOwner="PayPal", #AddressStatus="None">
Thanks in advance
I am not sure if you are using this gem 'paypal-sdk-rest'
but if you are, when you Create Payment
you can do
require 'paypal-sdk-rest'
include PayPal::SDK::REST
PayPal::SDK::REST.set_config(
:mode => "sandbox", # "sandbox" or "live"
:client_id => "EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM",
:client_secret => "EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM")
# Build Payment object
#payment = Payment.new({
:intent => "sale",
:payer => {
:payment_method => "credit_card",
:funding_instruments => [{
:credit_card => {
:type => "visa",
:number => "4567516310777851",
:expire_month => "11",
:expire_year => "2018",
:cvv2 => "874",
:first_name => "Joe",
:last_name => "Shopper",
:billing_address => {
:line1 => "52 N Main ST",
:city => "Johnstown",
:state => "OH",
:postal_code => "43210",
:country_code => "US" }}}]},
:transactions => [{
:item_list => {
:items => [{
:name => "item",
:sku => "item",
:price => "1",
:currency => "USD",
:quantity => 1 }]},
:amount => {
:total => "1.00",
:currency => "USD" },
:description => "This is the payment transaction description." }]})
# Create Payment and return the status(true or false)
if #payment.create
#payment.id # Payment Id
else
#payment.error # Error Hash
end
I hope that this helps.
ps.
you have to request the info first, if not there would be nil or '' when you want to get them back

How to display Order id in paypal transaction detail page?

we are using rails4 , activemerchant 1.47.0 .
Normally, order id is not showing in transaction detail page for a transaction of a order in paypal.
How can we set the order id in transaction detail page of a paypal transaction ?
These are the methods used for a transaction and purchase.
response = ACTIVE_GATEWAY.setup_purchase((payment.amount * 100),
ip: request.remote_ip,
return_url: "url",
cancel_return_url: url,
currency: "USD",
items: [{name: order.number, description: "Order description", quantity: "1", amount: (payment.amount * 100)}]
)
redirect_to ACTIVE_GATEWAY.redirect_url_for(response.token)
Purchase
purchase_response = ACTIVE_GATEWAY.purchase((payment.amount* 100), {
:ip => request.remote_ip,
:token => token,
:payer_id => payerID
})
Thanks
Please try like this.
This is for development environment.
config/development.rb
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
:login => "email_id",
:password => "password",
:signature => "signature"
}
::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
end
Controller::
def express_paypal
order = current_user.orders.find(params[:id])
amount = order.total_amount
response = EXPRESS_GATEWAY.setup_purchase(amount,
:ip => request.remote_ip,
:return_url => url_for(:action => 'complete', :id => order.id),
:cancel_return_url => url_for(:action => 'show', :controller => "orders",:id => order.id),
:allow_guest_checkout => true,
:items =>
[{ :name => current_user.to_s,
:quantity => 1,
:description => "Items",
:amount => amount
}]
)
if response.present?
redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
end
end
def complete
order = current_user.orders.find(params[:id])
amount = order.total_amount
begin
purchase = EXPRESS_GATEWAY.purchase(amount,
:ip => request.remote_ip,
:payer_id => params[:PayerID],
:token => params[:token]
)
rescue Exception => e
logger.error "Paypal error while creating payment: #{e.message}"
flash[:error] = e.message
end
unless purchase.success?
flash[:error] = "Unfortunately an error occurred:" + purchase.message
else
flash[:notice] = "Thank you for your payment"
end
redirect_to :action => "show", :id => order.id
end

omniauth mock facebook response

I'm want to test my login through facebook. Im using pure omniauth, w/o Devise. I check the wiki page and do following:
helper for request specs
module IntegrationSpecHelper
def login_with_oauth(service = :facebook)
visit "/auth/#{service}"
end
end
spec_helper.rb
RSpec.configure do |config|
config.include IntegrationSpecHelper, :type => :request
end
Capybara.default_host = 'http://example.org'
OmniAuth.config.test_mode = true
OmniAuth.config.add_mock(:facebook, {
:provider => 'facebook',
:uid => '12345',
:user_info => {
:name => 'dpsk'
}
})
my spec
require 'spec_helper'
describe 'facebook' do
it "should login with facebook", :js => true do
login_with_oauth
visit '/'
page.should have_content("dpsk")
end
end
#OmniAuth routes
match "/auth/:provider/callback" => "sessions#create"
match "/signout" => "sessions#destroy", :as => :signout
match "/signin" => "sessions#signin", :as => :signin
match "/auth/failure" => "sessions#failure", :as => :auth_failure
But in spec nothing returns instead of my mock i got an error:
Failure/Error: visit "/auth/facebook"
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
Where is my error?
My problem was in the mock, its has wrong structure.
OmniAuth.config.mock_auth[:facebook] = {
'user_info' => {
'name' => 'Mario Brothers',
'image' => '',
'email' => 'dpsk#email.ru' },
'uid' => '123545',
'provider' => 'facebook',
'credentials' => {'token' => 'token'}
}
This structure worked for me (December 2016)
OmniAuth.config.mock_auth[:facebook] = OmniAuth::AuthHash.new({
'provider' => 'facebook',
'uid' => '123545',
'info' => {
'email' => 'dpsk#email.ru',
'name' => 'Mario Brothers',
'image' => '' },
'credentials'=> {
'token'=> '12345',
'expires_at' => 1486718672,
'expires' => true },
'extra' => {
'raw_info' => {
'email' => 'dpsk#email.ru',
'name' => 'Mario Brothers',
'id' => '12345' }
}
})

Resources