To run purchases automatically without needing customer’s continuous authorization,
You need to get baid (billing agreement id). Afterwards you can use Paypal
reference transaction API to do future purchases.
Below is an example using active merchant gem to run Paypal API
active merchant example to get paypal baid by paypal express checkout api
# Initialize Paypal APIdefinitialize@paypal||=activemerchant::billing::paypalexpressgateway.new(:login=><paypalemailaccount>,:password=><paypalpassword>,:signature=><paypalsignature>,end# Ask for user agreementdefcreatesetup_response=@paypal.setup_purchase(0,:return_url=><yourserverpath>,:cancel_return_url=><yourserverpath>,:description=><productdescription>,:currency=>"USD",:custom=>"a customized data",:billing_agreement=>{:type=>'MerchantInitiatedBilling',# Use this to retrieve BAID => Billing Agreement ID:payment_type=>"Any"# seemed optional})redirect_to@paypal.redirect_url_for(setup_response.token)end# Get BAIDdefcallbackresponse=@paypal.create_agreement(params[:token])ifresponse.success?baid=response.params["BillingAgreementID"]endend