recurring paypal with preapproval adaptive payment - ruby-on-rails

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.

Related

Stripe API in Rails

I'm trying to use source_transaction with the Rails API so that I can have managed accounts that create payments and are later sent to other accounts.
I'm getting the error Stripe::InvalidRequestError: Insufficient funds in Stripe account. In test mode, you can add funds to your available bal
ance (bypassing your pending balance) by creating a charge with 4000 0000 0000 0077 as the card number. You can use th
e the /v1/balance endpoint to view your Stripe balance (for more details, see stripe.com/docs/api#balance).
But usinrg source_transaction I thought was supposed to bypass using my balance and only transfer funds once the transaction cleared.
Here is the code I'm using
charge = Stripe::Charge.create(
:customer => stripe_cust_id,
:amount => total_amount_owed,
:description => 'Groundwork Subscription Charge',
:currency => 'usd',
:transfer_group => invoice_number
)
...
transfer = Stripe::Transfer.create({
:amount => amount_to_transfer,
:currency => "usd",
:destination => StripeInfo.where(account_id: project_owner.accounts.first.id).first.stripe_id,
:application_fee => (amount_to_transfer*0.05).round,
:source_transaction => charge[:charge_id]
# :transfer_group => invoice_number
})

Payflow payment integration in ruby on rails

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

How to get IPN notification in PayPal on localhost

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.

Fedex Plugin Rails

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.

Paypal adaptive payments for digital goods

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.

Resources