Set return method rm=2 while creating Billing Agreement Subscriptions using express checkout

noor1981
Contributor
Contributor

Hi All, Please let me know where can I set the return method rm=2 while doing a express checkout.  I am creating a recurring payment for subscription. I am creating Billing agreement. I am doing it in an Asp.Net Web api using c#. Below is my code where I am creating a Billing plan and agreement. I want the paypal response returned to this method only. It is a HttpPost mehtod in my web api.

 

// Create a billing plan and subscribe to it
        [HttpPost]
        [Route("~/subscribe")]
        public Response<string> Subscribe(PayPalInfo objPayPalInfo,string token) 
        {
            string[] paypalURL = new string[1];
            try
            {
                if(objPayPalInfo==null)
                {
                    return new Response<string>(Convert.ToInt32(HttpStatusCode.BadRequest), "Subscription information is missing", null);
                }
                if (objPayPalInfo.subscriptionDescription == null || objPayPalInfo.subscriptionName == null)
                {
                    return new Response<string>(Convert.ToInt32(HttpStatusCode.BadRequest), "Subscription Name, Subscription Description is required.", null);
                }
                if (objPayPalInfo.subscriberAddress == null || objPayPalInfo.subscriberCity == null ||
                   objPayPalInfo.subscriberCountryCode == null || objPayPalInfo.subscriberName == null
                   || objPayPalInfo.subscriberPostalCode == null)
                {
                    return new Response<string>(Convert.ToInt32(HttpStatusCode.BadRequest), "Subscriber Name, Address, City, Country Code, Postal Code is required.", null);
                }
                var plan = PayPalSubscriptionsService.CreateBillingPlan(objPayPalInfo.subscriptionName, objPayPalInfo.subscriptionDescription);

                //Fetch User details          
                var subscription = PayPalSubscriptionsService.CreateBillingAgreement(plan.id,
                    new PayPal.Api.ShippingAddress// need to pull these values from logged in user table
                {
                        city = objPayPalInfo.subscriberCity,
                        line1 = objPayPalInfo.subscriberAddress,
                        postal_code = objPayPalInfo.subscriberPostalCode,
                        country_code = objPayPalInfo.subscriberCountryCode
                    }, objPayPalInfo.subscriberName, objPayPalInfo.subscriptionName, DateTime.Now);

                 paypalURL[0] = subscription.GetApprovalUrl();
            }
            catch(Exception ex)
            {
                return new Response<string>(Convert.ToInt32(HttpStatusCode.BadRequest), ex.Message , null);
            }
            return new Response<string>(Convert.ToInt32(HttpStatusCode.OK),"Paypal URL returned sucessfully", paypalURL);
        }

When I confirm the payment using the paypal url returned by the above webapi call I want paypal to return response to my above web api call only.  But presently it shows error as it is Post method and hence cannot return the response. 

This is my return url

http://localhost:63808/Subscribe

 

Any help is appreciated.

 

Regards,

Noor

Login to Me Too
0 REPLIES 0

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.