I am struggling to figure out how to get Digital goods to work with my adaptive payments. I am using the Paypal ruby gem can someone please show me a code sample for a payments with 2 receivers and for Digital Goods?
I already am approved for micro payments by paypal.
# Build request object
#pay = #api.build_pay({
:actionType => "PAY",
:cancelUrl => "http://localhost:3000/account", #sandbox
:currencyCode => "USD",
#:feesPayer => "SENDER",
:ipnNotificationUrl => "http://596w.localtunnel.com/pay/#{purchased.id}", #sandbox
:memo => "Test payment",
:receiverList => {
:receiver => [{
:amount => price.round(2),
:email => "an email", #sandbox
:paymentType => "DIGITALGOODS",
:primary => true
},
unless account.user.email == "an email"
{
:amount => mycut.round(2),
:email => "anemail", #sandbox
:paymentType => "DIGITALGOODS"
}
end
] },
:returnUrl => "http://localhost:3000/pay/complete/" #sandbox
})
I get the error:
This feature (Digital Goods) is not supported.
As far as i know on the the Express Payment option of Paypal supports digital good. if you can replace your integration to use activemerchant and use the PaypalDigitalGoodsGateway you'd do yourself a favor.
Log a ticket at https://www.paypal.com/mts and they'll enable it for you.
For what it's worth, the product you're trying to use is: Digital Goods for Express Checkout.
Express Checkout itself is available by default on all accounts, but that team can enable Digital Goods on your Sandbox account.
This error may appear if you get the payKey successfully but redirect user to wrong url later.
Here is haml code for form for embedded payments, including Digital Goods.
= javascript_include_tag "//www.paypalobjects.com/js/external/apdg.js"
%form.text-center{:action => ::PAYPAL_ADAPTIVE_GATEWAY.embedded_flow_url, :target => "PPDGFrame"}
%input#type{:name => "expType", :type => "hidden", :value => "light"}
%input#paykey{:name => "payKey", :type => "hidden", :value => #payKey}
%input#submitBtn{:type => "submit", :value => 'Pay with PayPal' }
:javascript
var returnFromPayPal = function(){
//do something on PayPal popup closing here
};
var dgFlowMini = new PAYPAL.apps.DGFlowMini({ trigger: 'submitBtn', callbackFunction: returnFromPayPal});
//works only for lightbox mode
function MyEmbeddedFlow(embeddedFlow) {
this.embeddedPPObj = embeddedFlow;
this.paymentSuccess = function () {
this.embeddedPPObj.closeFlow();
// handle payment success here
window.location.reload(true);
};
this.paymentCanceled = function () {
this.embeddedPPObj.closeFlow();
// handle payment cancellation here
window.location.reload(true);
};
}
var myEmbeddedPaymentFlow = new MyEmbeddedFlow(dgFlowMini);
::PAYPAL_ADAPTIVE_GATEWAY.embedded_flow_url is from activemerchant, you may use 'https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay' for sandbox or 'https://www.paypal.com/webapps/adaptivepayment/flow/pay' for production.
Related
I'm using paypal for payment and here is main function and parameters which are used for payment.
def self.paypal_url(.....)
values = {
:business => 'email#id.com',
:cmd => '_cart',
:upload => 1,
:return => return_url,
:invoice => "#{customer.id}_#{sType.id}_#{Time.now}",
:notify_url => notify_url
}
values.merge!({
"amount_1" => amount,
"item_name_1" => sType.show_title,
"discount_amount_1" => discount
# "quantity_1" => '1'
})
"https://www.paypal.com/cgi-bin/webscr?" + values.to_query
end
But now i want to use PayFlow. Kindly guide me which parameter i have to change and what will be the final url as for payment is "https://www.paypal.com/cgi-bin/webscr?" + values.to_query.
Kindly guide me?
There is a Rails example of payflow pro with hosted pages on git:
https://gist.github.com/supairish/5872581
The code gets the token to use in an iframe in your view.
You can see an example here:
https://developer.paypal.com/docs/classic/payflow/gs_ppa_hosted_pages/
I also found this resource helpful:
How do I test my integration with the Payflow Gateway using the hosted pages?
www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1493
I am using Adaptive Payment in PayPal.
I am following the https://github.com/paypal/adaptivepayments-sdk-ruby.
All is working fine except I am not able to receive IPN notofications locally.
#api = PayPal::SDK::AdaptivePayments.new
#pay = #api.build_pay({
:actionType => "PAY",
:cancelUrl => "http://"+Rails.application.config.app_name+"/admin/dashboard",
:currencyCode => "USD",
:feesPayer => "SENDER",
:ipnNotificationUrl => "http://"+Rails.application.config.app_name+"/admin/receive_notification",
:receiverList => {
:receiver => [{
:amount => amount,
:email => #paypal_id }] },
:returnUrl => "http://"+Rails.application.config.app_name+"/admin/dashboard" })
So , how to receive notifications on localhost
Paypal will not be able to route to localhost to send the IPN. You would need to setup a publicly available domain name and the appropriate dns.
Localhost is always specific to your machine, you might be able to use dynamicdns but it would require network changes on your machine and network.
I have create rails application and implemented preapproval payment using adaptivepayments-sdk-ruby gem. I plan to use this as recurring payment.
this is my code for create preapproval:
ADAPTIVE_PAYMENT.build_preapproval({
:cancelUrl => my_cancel_url,
:currencyCode => "USD",
:paymentPeriod => "DAILY",
:returnUrl => my_return_url,
:startingDate => DateTime.now.in_time_zone
})
and then I use this code to charge:
ADAPTIVE_PAYMENT.build_pay({
:actionType => "PAY",
:cancelUrl => my_cancel_url,
:currencyCode => "USD",
:feesPayer => "PRIMARYRECEIVER",
:preapprovalKey => Preapproval_key,
:receiverList => {
:receiver => [{
:amount => 100,
:email => example#example.com,
:primary => true},
{
:amount => $100,
:email => example#example.com,
:primary => false }
]
},
:returnUrl => my_return_url
})
How to make it automatically charged every day without execute the pay code again?
Im pretty sure there is no automatic pay feature from paypals side. I know that you can setup how many monthly / weekly payments they are signing up for but I think thats just for the pre-approval agreement.
However, why dont you just setup a CRON job and let it take care of it for you? I was super nervous about doing this with paypal adaptive payments the first time but its actually saved me SO much time and its a lot more reliable than any human could be with its ability to send job reports after its done.
I working on an existing code base for a client. The app is built in rails 2.3 and uses the fedex plugin. Now i have develop a functionality for shipping the goods using international priority service type, the problem i'm facing is when ever i make a call to the fedex api for a shipping label it returns an error
"Fedex::FedexError: Unable to get label from Fedex: Customs Value is required"
Can some one help me how to mention the customs value for the label.
This is how my code is:
price, labels, tracking_number = fedex.label(
:shipper => { :contact => shipper, :address => origin },
:recipient => { :contact => recipient, :address => destination.merge(:residential => false) },
:service_type => service_type,
:packages => [{:length => 3,
:height => 4,
:width => 5,
:weight => 5,
}],
:weight => 5,
:commodities => commodities,
:customs_value =>{:currency => "USD", :amount => "100" },
:residential => is_residential_destination
)
Thanks in advance.
I am currently working on a Ruby-on-Rails web-application that accepts PayPal payments through PayPal's Express Checkout and ActiveMerchant. I have done several research on ActiveMerchant's support for determining if a customer/buyer has paid using either a verified or unverified PayPal account but I got no luck on finding a helpful guide.
I find it also that ActiveMerchant is currently not well-documented so it's not that helpful at all.
Below are the relevant codes that my project is currently using. On PaymentsController#purchase, I temporarily used the #params['protection_eligibility'] and the #params['protection_eligibility_type'] methods of the ActiveMerchant::Billing::PaypalExpressResponse object that is returned by the EXPRESS_GATEWAY.purchase method call, to assess if a PayPal customer/buyer has a verified/unverified PayPal account. Later I found out that this is not a reliable basis for knowing the customer's account status.
I hope somebody can give me a wisdom on knowing whether a PayPal customer/buyer has a verified/unverified account using Ruby-on-Rails' ActiveMerchant or using other alternatives on Rails.
# config/environments/development.rb
config.after_initialize do
ActiveMerchant::Billing::Base.mode = :test
paypal_options = {
# credentials removed for this StackOverflow question
:login => "",
:password => "",
:signature => ""
}
::EXPRESS_GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new(paypal_options)
end
# app/models/payment.rb
class Payment < ActiveRecord::Base
# ...
PAYPAL_CREDIT_TO_PRICE = {
# prices in cents(US)
1 => 75_00,
4 => 200_00,
12 => 550_00
}
STATUSES = ["pending", "complete", "failed"]
TYPES = ["paypal", "paypal-verified", "paypal-unverified", "wiretransfer", "creditcard"]
# ...
end
# app/controllers/payments_controller.rb
class PaymentsController < ApplicationController
# ...
def checkout
session[:credits_qty] = params[:credit_qty].to_i
total_as_cents = Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
setup_purchase_params = {
:allow_guest_checkout => true,
:ip => request.remote_ip,
:return_url => url_for(:action => 'purchase', :only_path => false),
:cancel_return_url => url_for(:controller => 'payments', :action => 'new', :only_path => false),
:items => [{
:name => pluralize(session[:credits_qty], "Credit"),
:number => 1,
:quantity => 1,
:amount => Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
}]
}
setup_response = EXPRESS_GATEWAY.setup_purchase(total_as_cents, setup_purchase_params)
redirect_to EXPRESS_GATEWAY.redirect_url_for(setup_response.token)
end
def purchase
if params[:token].nil? or params[:PayerID].nil?
redirect_to new_payment_url, :notice => I18n.t('flash.payment.paypal.error')
return
end
total_as_cents = Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
purchase_params = {
:ip => request.remote_ip,
:token => params[:token],
:payer_id => params[:PayerID],
:items => [{
:name => pluralize(session[:credits_qty], "Credit"),
:number => 1,
:quantity => 1,
:amount => Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
}]
}
purchase = EXPRESS_GATEWAY.purchase total_as_cents, purchase_params
if purchase.success?
payment = current_user.payments.new
payment.paypal_params = params
payment.credits = session[:credits_qty]
payment.amount = Payment::PAYPAL_CREDIT_TO_PRICE[session[:credits_qty]]
payment.currency = "USD"
payment.status = "complete"
if(purchase.params["receipt_id"] && (purchase.params["success_page_redirect_requested"] == "true"))
payment.payment_type = "creditcard"
else
if purchase.params['protection_eligibility'] == 'Eligible' && purchase.params['protection_eligibility_type'] == 'ItemNotReceivedEligible,UnauthorizedPaymentEligible'
payment.payment_type = 'paypal-verified'
else
payment.payment_type = 'paypal-unverified'
end
end
payment.ip_address = request.remote_ip.to_s
payment.save!
SiteMailer.paypal_payment(payment).deliver
SiteMailer.notice_payment(payment).deliver
notice = I18n.t('flash.payment.status.thanks')
redirect_to profile_url, :notice => notice
else
notice = I18n.t('flash.payment.status.failed', :message => purchase.message)
redirect_to new_payment_url, :notice => notice
end
end
# ...
end
I used PayPal's paypal-sdk-merchant gem to do the job ActiveMerchant wasn't able to help me with (getting the status of a payer's account: verified/unverified PayPal account. I followed the installation of paypal-sdk-merchant on https://github.com/paypal/merchant-sdk-ruby
gem 'paypal-sdk-merchant'
bundle install
rails generate paypal:sdk:install
Then I set-up their samples https://github.com/paypal/merchant-sdk-ruby#samples. After setting-up the samples, go to /samples of your Rails app and you will find a lot of code generator for what ever function you need from PayPal's API. Don't forget to configure your config/paypal.yml. I configured the username, password and signature (can be obtained from your PayPal sandbox specifically your test seller account) and removed the app_id in my case.
I obtained the following code for getting a PayPal payer's account status (verified/unverified) using PayPal's samples (/samples) and placed it on a class method of a model in my app:
def self.get_paypal_payer_status(transaction_id)
require 'paypal-sdk-merchant'
api = PayPal::SDK::Merchant::API.new
get_transaction_details = api.build_get_transaction_details({
:Version => "94.0",
:TransactionID => transaction_id
})
get_transaction_details_response = api.get_transaction_details(get_transaction_details)
get_transaction_details_response.payment_transaction_details.payer_info.payer_status
end
I'm not familiar with ActiveMerchant so I can't tell you specific to that, but with any Express Checkout implementation you can use GetExpressCheckoutDetails to obtain the payers information which will include a PAYERSTATUS parameter with a value of "verified" or "unverified".
It's an optional call, but I would assume ActiveMerchant is probably including it so you just need to track that down and pull that parameter accordingly.
Alternatively, you can use Instant Payment Notification (IPN) to receive transaction information and you will get back a payer_status parameter here as well.