Paypal recurring payment and billing period - php

I am using PayPal-php-sdk .I had successfully implemented recurring payment using this rest api . Currently the payment occurring in each end of the month.
But I want to charge immediately when the user subscribe ie the first payment will charged when user subcribe the plan. How can I implement this ? Please any one help.

I created mine to where I have a set up fee which charges immediately and then I set the regular payments to begin 1 month later.
$merchantPreferences->setReturnUrl("$baseUrl/paypal/ExecuteAgreement?success=true")
->setCancelUrl("$baseUrl/paypal/ExecuteAgreement?success=false")
->setAutoBillAmount("yes")
->setInitialFailAmountAction("CONTINUE")
->setMaxFailAttempts("0")
->setSetupFee(new Currency(array('value' => 8.50, 'currency' => 'USD')));
I hope this helps.

It is likely that you are encountering a bug in the PayPal Sandbox.
Please report it to PayPal Merchant Support.

If you don't offer free trial period the user must pay for the first cycle immediately. If you offer free trial period, you can control the sequence of the cycles to have the paid one first and then the trial one.

Related

How to detect recurring payment transaction in PayPal

I am building a website which sells some web services. My clients will be charged monthly. I followed the document instructions (enter link description here) and after I execute the agreement. Nothing happened. After I wait for one night, I found that my test client account (sandbox account) was charged the trial amount and it said the payment is pre-approved, and my business account (sandbox account) didn't receive this payment.
So now I have the following problems about this recurring payment. Please help me about this. Thank you very much in advance.
Q1: How to charge initial payment in recurring payment? In my text client account, the initial payment of this recurring agreement is $0
Q2: How to know when the recurring payment is done? I want to record the transaction in my database and send receipt to my client after each payment.
Updated
I have implemented IPN to get notifications about recurring agreement created/suspended/cancelled. But I didn't find which type of notification is used after each recurring payment, and I still didn't find how to charge initial payment.
I will try using set up fee and I will post the results when the test is done.
Update 1
Confirmed. The set up fee is used as initial payment. See this for more details.

PayPal API with PHP - single payment, then recurring payment with different amount

I am using the following code to send a payment request to PayPal's API (the $field array in the $paypal class is used to build a POST request). This code works fine.
$paypal = new paypal_class;
$paypal->add_field('business', $store_email);
$paypal->add_field('return', $script_location.'?action=success&order_id='.$order_id);
$paypal->add_field('cancel_return', $script_location.'?action=cancel');
$paypal->add_field('notify_url', $script_location.'?action=ipn');
$paypal->add_field('item_name_1', strip_tags(str_replace("'","",$_POST["description"])));
$paypal->add_field('amount_1', $amount);
$paypal->add_field('item_number_1', $item_id);
$paypal->add_field('quantity_1', '1');
$paypal->add_field('custom', $_SERVER['REMOTE_ADDR']);
$paypal->add_field('upload', 1);
$paypal->add_field('cmd', '_cart');
$paypal->add_field('txn_type', 'cart');
$paypal->add_field('num_cart_items', 1);
$paypal->add_field('payment_gross', $amount);
$paypal->add_field('currency_code', strip_tags(str_replace("'","",$_POST["currency"])));
$paypal->submit_paypal_post(); // submit the fields to paypal
Now, let's say the $amount I'm sending is $199. This amount will be charged correctly using the code above. Now I want to charge $29 per year in addition to the initial $199. Can I modify the code above (sending some extra fields presumably) to accomplish this?
I've been looking through the docs and I've seen some options for recurring billing but can't find one for exactly what I'm looking for - which is an initial payment of Amount X and then recurring payments of Amount Y.
You can offer a trial period of any amount including 0. The Trial period is the initial payment and after the trial period is over then you can setup the actual subscription amount, and start the billing on a specific date.
Here is the documentation for Express Checkout:
Express Checkout Recurring with Trial Period
&TRIALBILLINGPERIOD=Month #Period of time in one trial period
&TRIALBILLINGFREQUENCY=1 #Frequency of charges, if any, during the trial period
&TRIALTOTALBILLINGCYCLES=1 #Length of trial period
&TRIALAMT=0 #Payment amount (can be 0) during the trial period
&CURRENCYCODE=USD #The currency, e.g. US dollars
Here is the documentation for direct Recurring Payments
Trial Period for Direct Recurring Payments
It looks like you're working with Payments Standard. Can you confirm that?
If so, the answer pp_MSI_Jenn gave isn't going to apply. That said, I would recommend you switch to Express Checkout if you're comfortable with PHP class (which apparently you are.) This class library will make Express Checkout very simple for you.
You'll be working with the following API's.
SetExpressCheckout
GetExpressCheckoutDetails
CreateRecurringPaymentsProfile
Since you mentioned that you want to charge a one-time amount of $199 and then $29/year after that, you actually don't need to mess with a trial period. Instead, you'll just use the INITAMT parameter in the CRPP request to process the $199. Then you'll use the regular AMT, BILLINGPERIOD, BILLINGFREQUENCY, etc. to setup the $29/year, but you'll set the PROFILESTARTDATE to be 1 year from the current date. That way the first $29 payment won't happen for 1 year, but you'll get the $199 right away when the profile is created.
If you'd rather stick with Payments Standard, then you actually could utilize the trial period as a work-around the way pp_MSI_Jenn mentioned doing with Express Checkout. You would set the trial period for 1 year and use the $199 amount for that period, and then set the regular period to $29/year.
For more details on that look at the Sandard Varaibles list, specifically the recurring payments section.

Paypal Sandbox recurring payment with initial amount pending

I'm using the PHP library here to create a new subscription profile. If I set an initial amount, the profile appears as "Pending".
Example:
Pending
Customer Mark Wally Verified
Profile start date Feb 18, 2013 | Profile ID I-BE824P6F9PER
On the other hand, if I set no initial payment amount, the profile will be "Active". I am setting the initial payment and the start date 1 month in the future since I want to bill monthly and get a payment right away.
I've already verified:
Account is set to accept money in any currency
The seller account has digital goods enabled (created via automated process)
Both accounts are verified
The buyer account has a credit card as well as a paypal balance
Both accounts are US based
I've tried with multiple accounts
Any help would be greatly appreciated!
Code snippet to create the subscription that use the library listed above:
$subscription_details = array(
'description' => 'Premium membership: $4.95 every 30 days',
'initial_amount' => '4.95',
'amount' => '4.95',
'period' => 'Day',
'start_date' => gmdate( 'Y-m-d\TH:i:s', strtotime( '+30 day' ) ),
'frequency' => '30'
);
Just in case someone else has this trouble, my findings are:
There is nothing to solve -- the sandbox is just really slow, sometimes it took a couple days for the profile to become active and send the IPN. In other words, sandbox isn't good to test these functions at all, just go live and refund a couple tests. Even live sometimes takes a bit of time... I've seen it take a few hours sometimes, so don't go crazy.
From PayPal doco:
"By default, PayPal does not activate the profile if the initial payment amount fails. To override this default behavior, set the FAILEDINITAMTACTION field to ContinueOnFailure. If the initial payment amount fails, ContinueOnFailure instructs PayPal to add the failed payment amount to the outstanding balance due on this recurring payment profile.
If you do not set FAILEDINITAMTACTION or set it to CancelOnFailure, PayPal creates the recurring payment profile. However, PayPal places the profile into a pending status until the initial payment completes. If the initial payment clears, PayPal notifies you by Instant Payment Notification (IPN) that it has activated the pending profile. If the payment fails, PayPal notifies you by IPN that it has canceled the pending profile"
from https://cms.paypal.com/mx/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_WPRecurringPayments, just below Table 6.

How to create a paypal recurring payment with an initial amount to pay?

I am currently creating a paypal payment with recurring support. I want it
in such a way that there is an initial payment made.
Example :
30$ - initial payment
10$ - recurring monthly payment
The initial payment is charge upon checkout. I'm using the html standard
integration process.
Is it possible?
Using paypal NVP API for PHP, you can send the initial payment to paypal like this.
$nvpstr="&AMT=10&CREDITCARDTYPE=$creditCardType&ACCT=$creditCardNumber&EXPDATE=". $padDateMonth.$expDateYear."&CVV2=$cvv2Number&FIRSTNAME=$firstName&LASTNAME=$lastName&STREET=$address1&CITY=$city&STATE=$state".
"&ZIP=$zip&COUNTRYCODE=US&CURRENCYCODE=$currencyCode&PROFILESTARTDATE=$profileStartDate&DESC=$profileDesc&BILLINGPERIOD=$billingPeriod&BILLINGFREQUENCY=$billingFrequency&TOTALBILLINGCYCLES=$totalBillingCycles&INITAMT=30.00";
$resArray=hash_call("CreateRecurringPaymentsProfile",$nvpstr);
parameter INITAMT specifies the initial payment amount
Yes, this is possible with Website Payments Standard (the 'HTML standard integration process' I assume you use). Simply include a trial period within the subscription, and start charging X days from when subscriptions ends.
See the subscription variables here.
I too switched from website payment's pro to html integration and unfortunately initial amount option is not available in HTML version. If you can switch website payments pro and use API then you can have the option of initial amount (I had to switch because API is not allowed on Israel paypal accounts) otherwise the only option you have in HTML is trial periods.
But on the below link the INTAMT is not proper way to deduct initial payment
Paypal recrurring payments
So please put your thoughts.

Change the amount paid per month of paypal recurring payment account

The situation is like this,
I have three kind of user registration on my site
$20/month
$30/month
$40/month
now, suppose a user registers with $30 amount and takes the 2nd registration...
next 2 months his $30 per month were deducted as per the recurring payment of paypal...working fine .:)
Now, he wants to upgrade to $40 i.e 3rd membership , so from next month his amount deduction should be $40... How to update paypal for this change in amount..
I DON'T WANT TO GO TO PAYPAL'S SITE FOR THIS...
Is there any API for this purpose.......
Any help would be appreciated....
First off, Paypal's API is not a simple or easy thing to use, but what you're asking can be done. It is simply a matter of canceling the existing 'recurring payment profile' via the API, and starting another recurring payment that ends at the same time.
The API methods themselves change depending on which system you are using. At my company, we use Paypal Website Payments Pro. This has a specific set of functions to perform actions. Without knowing which system you use, however, we can't give any further advice.
The below link shows a number of the methods for the different Paypal API's. Do your research, and try to ask specific questions. :)
https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/howto_api_reference
Daniel Moniz
I was able to do this, but first, this caveat from PayPal should be noted:
Note: For recurring payments with Express Checkout, the payment amount can be increased by no more than 20% every 180 days (starting when the profile is created).
Since I'm not using Express Checkout, POSTing this worked for me to change an amount from $75 to $200 (the credentials are fake):
TRXTYPE=R&TENDER=C&PARTNER=PayPal&VENDOR=Acme&USER=Acme&PWD=a1b2c3d4
&ACTION=M&AMT=200.00&ORIGPROFILEID=RP0000001234
The other caveat is that this is only one of I-don't-know-how-many APIs and I-don't-know-how-many-types-of-accounts (in this case Payflow) that PayPal has, and I don't know if something similar works for all of them. The above code is actually copied almost verbatim (credentials and amount changed) from https://developer.paypal.com/docs/classic/payflow/recurring-billing/.

Categories