Paypal IPN get subscription end date (recurring) - paypal

I'm developing a site that has annual or monthly paypal subscription options. From the IPN data that receives, can I determine if the subscription is annual or monthly? Doesn't seem possible.
At the moment it's set up just for monthly payments, so in my own db I store something along the lines of:
$data = array(
'id' => $ipnData['custom'],
'subscribed' => 1,
'subscription_fee' => $ipnData['mc_amount3'],
'subscribed_until' => date("Y-m-d H:i:s",strtotime($ipnData['subscr_date'] . '+1 Month'))
);
You'll see I'm using the subscription_date variable and just incrementing it by a month. But now, potentially subscriptions can be annual, and I need somehow to get the date in which the next payment would be taken. This doesn't seem to be a variable? A return of the original T3 would be great.
I can do this with custom fields, but that seems a bit daft. Cheers.

PayPal will send a notification when the subscription ends:
txn_type = "subscr_eot"
The moment you receive this is the moment the subscription expires. This is when you would downgrade/cancel their account. Note that this is different from txn_type="subscr_cancel" which is triggered when a user cancels their subscription; this could be the day after they subscribe and they may have time remaining on the subscription. In this case you will still receive the subscr_eot when the time runs out.
I also found this to be a bit counter-intuitive.

Related

PayPal Soap API Balance for certain Date

I'm using the PayPal Soap-Api.
With the "GetBalance"-Api Operation it's possible to get the current Balance.
But for Accounting reasons, I need to fetch the Balance for every Day in a certain period. e.g.
22.01.2016, Balance: 500,00 €
21.01.2016, Balance: 425,00 €
20.01.2016, Balance: 964,60 €
...
01.01.2015, Balance: 0,00 €
I found no Api-Operation that would match my needs.
So I tried to use the "TransactionSearch"-Api Operation to get the Transactions for this period and calculate the Balance.
Since there is no documentation wether a Transaction is balance-affecting or not, my calculation always failed.
It is possible to set certain filters for the "TransactionSearch"-Api Operation like "BalanceAffecting". But also with this filter set, I get the wrong Transactions to calculate the Balance for every day.

need explanation for PayPal recurring options: BILLINGPERIOD, BILLINGFREQUENCY, TOTALBILLINGCYCLES

https://developer.paypal.com/docs/classic/express-checkout/integration-guide/ECRecurringPayments/
I understand that setting BILLINGPERIOD to MONTH and BILLINGFREQUENCY to 1 will charge the user once a month.
But according to the above link, TOTALBILLINGCYCLES is optional and is set to 0 by default. So if I don't include that option, will the user be charged once a month forever or stopped after charging for the first year (12 times)?
Also, I want to charge the user for the first year only. What should i do? Should i set TOTALBILLINGCYCLES to 1 to achieve it?
Please advise.
Thanks
Please find TOTALBILLINGCYCLES in the link below:
https://developer.paypal.com/webapps/developer/docs/classic/api/merchant/CreateRecurringPaymentsProfile_API_Operation_NVP/
For the regular payment period, if no value is specified or the value is 0, the regular payment period continues until the profile is canceled or deactivated.
If you want to charge the user for the first year only, TOTALBILLINGCYCLES depends on your billing period.
If you set BILLINGPERIOD=Month and BILLINGFREQUENCY=1, you should set TOTALBILLINGCYCLES=12 to charge one year.
If you set BILLINGPERIOD=Year and BILLINGFREQUENCY=1, you should set TOTALBILLINGCYCLES=1 to charge one year.

PayPal billing agreements REST API - how to start immediately

How can I start charging a user the user immediately for a PayPal billing agreement?
Here's what I've got so far.
Create a Billing Plan (POST .../payments/billing-plans/)
Make it active (PATCH .../payments/billing-plans/)
Create a Billing Aggreement (POST .../payments/billing-agreements/)
Send user to approval_url, user approves, redirected to return url
Execute agreement (POST .../payments/billing-agreements//agreement-execute)
This all seems to work, but I want to charge the user right now and every month in the future. If I set start_date to now in step 3 I get an error, it must be in the future. If I set it in the future the user is not charged.
Do I need to 'Set outstanding agreement amounts' then 'Bill outstanding agreement amounts' for the initial payment?
Also, what about monthly payments, do they require some action or do they just happen as specified in the Billing Plan?
Update
I'm testing this around 2014-09-16T20:06:30+0000
If I send start_date as the current UTC time it get an error at step 2 telling me it must be in the future.
If I send the current date +30 secs or +2 hours I get through to step 5 which returns a 400 response: UNKNOWN_ERROR "An unknown error has occurred"
If I send the current date +4 hours it all works. The current UTC time is 8pm so adding 4 hours means the start_date is tomorrow.
Does this mean I can't charge the user today? Does the start_date have to be in next day or even the next business day?
I've talked to a PayPal rep and found that start_date must be tomorrow or later. They are going to add this to the docs.
If you want to start monthly billing immediately you might be able to do it by setting the start date to be in one months time and charging a setup fee to cover the first month. I haven't tested this as it's not what I want.
First payment for agreements will be billed right on specified start_date. The subsequent amounts are also taken automatically by PP. You need to work with the BillOutstandingAmount calls only if PP failed to pick the payment on the renewal date.
The problem I faced when developing with their RestAPI was specifying a wrong timezone. Maybe this is the same for you. Make sure the proper timezone is specified in your start_date (with all dates given to PP in fact)
Dates should be in this format: yyyy-MM-ddTHH:mm:ssZ
ex. start_date = 2014-09-16T09:20:00-0400
IF you want to make sure Paypal accepts the date as being valid, just add a few seconds to it.
Let's say you are in Java, you can do something like:
private String getPaypalDate()
{
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
// Add 30 seconds to make sure Paypal accept the agreement date
Date rightNow = new Date(new Date().getTime() + 30000);
return df.format(rightNow);
}
I used this date format working.
$time = time();
$startDate = date('Y-m-d\\TH:i:s\\Z', $time);
I can't replicate, actually. I stumbled on this thread when getting the error due to setting it to moment.now(). But setting it to even 5 seconds in the future works a-ok. I'm using JavaScript, "start_date": moment().add({seconds:5}).format() and that checks out fine. Moment.js will set TZ to UTC when formatting as such, so it's gotta be a timezone thing on your end?
It looks like the payments just process based on the date being before or after 07:00 UTC of the current date.
For example. The current date time is 2017-05-04T04:50:00.00Z I set my start date to be the current UTC date time plus 30 seconds. Because the agreement date is set to a value greater then the current date time the API doesn't throw an error, but it DOESN'T set your time to be what you specified. Instead it sets it to 2017-05-04T07:00:00Z.
Now, if you have the same date time of 2017-05-04T04:50:00.00Z and instead of adding 30 seconds you add 24hrs you'd think that your time would then be set to be 2017-05-05T04:50:00.00Z. But no, the time will be set to 2017-05-05T07:00:00Z.
So it seems like these just process everyday at 07:00 UTC and you can't specify anything but the date.

testing recurring payments using cmd=_xclick-subscriptions

I've got a form which is automatically submitted to paypal. If someone signs up for a recurring subscription, the following fields are added to the form:
cmd=_xclick-subscriptions
a3=(dollar amount)
p3= (billing frequency)
t3= (billing period)
p3 and t3 are always 1 and M (once every month). Read a paypal document which said changing that to once every day would actually force the recurring payments to happen every minute instead of day. I tried doing this but it's not rebilling every minute.
Is there something else i have to do in order to trigger a recurring payment?
In t3 here M stands for month not for minute, so t3=M and p3=1 means every month.

account's balance at a point of time in AggCat

Is there anyway to obtain an account's info including account's balance at a point of time? Basically, I need to get the account's balance at the beginning of month and end of month for accounting purposes. However, a cron job to update account's info at the beginning/end of month may fail for various reasons, in which case there is no way to retrieve account's balance at beginning/end of month anymore!
We do not have a mechanism to capture the value at a specific time as you are asking but provide a balance each time you capture the transactions. If you capture a day later you can always perform a reverse running balance using the current balance - the transactions that occured between the data you wish to display.
Example:
August 1st:
$5.00 Transaction to McDonalds
$3.00 Transaction to Ralphs
Balance on August 2nd:
$35.00
Calculate Balance for the 1st.
$35 + 5 + 3= $43.00 balance at start of month.
You add the debits and subtract the credits and you can obtain the value you are seeking.