Detecting paypal subscription cancel on login asp.net - c#

I am building an asp.net web app that involves paypal subscriptions. I need to check if the user has cancelled on login is this possible and if so how? I have seen other posts on this subject but my situation is different since I'll be checking on login. I was thinking maybe I can do a batch dump of data from paypal nightly and check against that to set a flag on the users that cancelled. Not sure what the best way to do this is..

If you want to check whether the user has accepted or cancelled the agreement after logging to the PayPal then yes you can check this by using the Express Checkout Token . You need to call GetExpressCheckoutDetails API on the Token after the buyer log in to the PayPal account and look for the variable BILLINGAGREEMENTACCEPTEDSTATUS in the response .
BILLINGAGREEMENTACCEPTEDSTATUS=0 means buyer has not accepted the agreement or clicked on cancel after logging to the PayPal account .
BILLINGAGREEMENTACCEPTEDSTATUS=1 , means by has clicked on the "agree and continue" after logging to the PayPal .
I have included some sample response .
For rejection after log in :
NVP Response:
TOKEN=EC-0RC04801KU663840M
**BILLINGAGREEMENTACCEPTEDSTATUS=0**
CHECKOUTSTATUS=PaymentActionNotInitiated
TIMESTAMP=2014-09-14T14:54:43Z
CORRELATIONID=5cc68231a1b35
ACK=Success
VERSION=109.0
BUILD=12786467
EMAIL=XXXXXXXXXXXXXX
PAYERID=XXXXXXXXXXXX
PAYERSTATUS=verified
FIRSTNAME=Eshan Personal Test
LASTNAME=Account
COUNTRYCODE=US
CURRENCYCODE=USD
AMT=0.00
SHIPPINGAMT=0.00
HANDLINGAMT=0.00
TAXAMT=0.00
INSURANCEAMT=0.00
SHIPDISCAMT=0.00
PAYMENTREQUEST_0_CURRENCYCODE=USD
PAYMENTREQUEST_0_AMT=0.00
PAYMENTREQUEST_0_SHIPPINGAMT=0.00
PAYMENTREQUEST_0_HANDLINGAMT=0.00
PAYMENTREQUEST_0_TAXAMT=0.00
PAYMENTREQUEST_0_INSURANCEAMT=0.00
PAYMENTREQUEST_0_SHIPDISCAMT=0.00
PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false
PAYMENTREQUEST_0_ADDRESSNORMALIZATIONSTATUS=None
PAYMENTREQUESTINFO_0_ERRORCODE=0
For acceptance after log in :
NVP Response:
TOKEN=EC-1EX65013S71914041
PHONENUM=408-767-7151
**BILLINGAGREEMENTACCEPTEDSTATUS=1**
CHECKOUTSTATUS=PaymentActionNotInitiated
TIMESTAMP=2014-09-14T14:56:24Z
CORRELATIONID=aae4de7a4b356
ACK=Success
VERSION=109.0
BUILD=XXXXXXXXXXXXX
PAYERID=XXXXXXXXXXXXXX
PAYERSTATUS=verified
FIRSTNAME=Eshan Personal Test
LASTNAME=Account
COUNTRYCODE=US
SHIPTONAME=Eshan Personal Test Account
SHIPTOSTREET=cxas
SHIPTOSTREET2=asa
SHIPTOCITY=FL
SHIPTOSTATE=FL
SHIPTOZIP=95616
SHIPTOCOUNTRYCODE=US
SHIPTOCOUNTRYNAME=United States
ADDRESSSTATUS=Confirmed
CURRENCYCODE=USD
AMT=0.00
SHIPPINGAMT=0.00
HANDLINGAMT=0.00
TAXAMT=0.00
INSURANCEAMT=0.00
SHIPDISCAMT=0.00
PAYMENTREQUEST_0_CURRENCYCODE=USD
PAYMENTREQUEST_0_AMT=0.00
PAYMENTREQUEST_0_SHIPPINGAMT=0.00
PAYMENTREQUEST_0_HANDLINGAMT=0.00
PAYMENTREQUEST_0_TAXAMT=0.00
PAYMENTREQUEST_0_INSURANCEAMT=0.00
PAYMENTREQUEST_0_SHIPDISCAMT=0.00
PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED=false
PAYMENTREQUEST_0_SHIPTONAME=Eshan Personal Test Account
PAYMENTREQUEST_0_SHIPTOSTREET=cxas
PAYMENTREQUEST_0_SHIPTOSTREET2=asa
PAYMENTREQUEST_0_SHIPTOCITY=FL
PAYMENTREQUEST_0_SHIPTOSTATE=FL
PAYMENTREQUEST_0_SHIPTOZIP=95616
PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=US
PAYMENTREQUEST_0_SHIPTOCOUNTRYNAME=United States
PAYMENTREQUEST_0_ADDRESSSTATUS=Confirmed
PAYMENTREQUEST_0_ADDRESSNORMALIZATIONSTATUS=None
PAYMENTREQUESTINFO_0_ERRORCODE=0

Related

PayPal: After Check whether subscriber is paid for subscription

I'm creating website using reactjs for frontend and for backend I'm using c# asp .net mvc. I have already integrated paypal subscription in whichevery month fixed amount deducted form his account(which I have already done) by following this link https://medium.com/analytics-vidhya/paypal-subscription-in-react-1121c39b26be. and here is my code.
window.paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'subscribe'
},
createSubscription: function(data, actions) {
return actions.subscription.create({
'plan_id': 'my-plan-id'
});
},
onApprove: function(data, actions) {
alert(data.subscriptionID);
console.log(data)
},
onError: (err) => {
console.log(err)
}
}).render(paypal.current)
but my requirement is when user login first time user must provide his paypal account details and after providing paypal account info check user has sufficient amount in his account proceed to dashboard. But my problem is how to handle if user has no balance in his account or unpaid and in this case after login user redirected to specific page not dashboard.
In short: how to check user is paid or unpaid if paid proceed to dashboard else redirect to specific page.
how to check user is paid or unpaid if paid proceed to dashboard else redirect to specific page.
The answer to this is to consult your database, which should have this information stored (whether a payment has been made, or whether the subscription is current) and allow you to determine what to do based on the information you have.
So your real question must be how to receive notifications from PayPal that a subscription payment has been made. For that, I will refer you to the answer in here: How do you know if a user has paid for a subscription
As for how to match subscription payments to users -- when a subscription is created, you can store its ID associated with your user, which is easiest to do if you activate the subscription from the server as discussed above. You can also pass a custom_id field during subscription creation, which can contain your own user ID for reconciliation.

MVC logout all active sessions after same user login

I have c# mvc web application.There is simple login page according to email and password. Now I have a need like that:
When a user login to the system, all active sessions that same email address will logout.
How can I achieve this?
You can use Session.Abandon() or Clear() to abandon the current session, but if there are multiple people logged in with the same address, this will not address that.
You'd have to build that detection in; for instance, you could update a flag on the table that represents your users and then in the other user's sessions periodically check the table if they were re-logged in. OR when a user logs in, create a token in a database table with an expiration date; associate that token to a user in a cookie. When logged out or logging back in, you could invalidate the token associated to that email address, and each user, when they attempt to access the application, could be rejected by your application checking whether the token is expired.
The Abandon method should work (MSDN):
Session.Abandon();
If you want to remove a specific item from the session use (MSDN):
Session.Remove("YourItem");
If you just want to clear a value you can do:
Session["YourItem"] = null;
If you want to clear all keys do:
Session.Clear();
If none of these are working for you then something fishy is going on. I would check to see where you are assigning the value and verify that it is not getting reassigned after you clear the value.
Simple check do:
Session["YourKey"] = "Test"; // creates the key
Session.Remove("YourKey"); // removes the key
bool gone = (Session["YourKey"] == null); // tests that the remove worked

IPN of recurring payments in Paypal have any different parameters than the normal invoice payment?

I'm developing a IPN listener wich must be able to catch recurring payments, invoice payments and subscriptions payments. I already reviewed to much documentation about this topic.
I hope someone can tell me the main differences between the POST that paypal sends to my listener on when the txn_type variable when it changes their value to:
txn_type=invoice_payment
txn_type=recurring_payment
txn_type=subscr_payment
I already has made a transaction with txn_type=invoice_payment, here is the IPN resend:
invoice_number=0003
invoice_id=XXXX-XXXX-XXXX-XXXX-XXXX
mc_gross_1=58.00
mc_handling1=0.00
num_cart_items=1
payer_id=DJ77XLF8321SCCQ
address_country_code=
ipn_track_id=901559bfkk956f2d
address_zip=6546
invoice=xxxx-xxxx-xxxx-xxxx-xxxx
charset=windows-1252
payment_gross=
address_status=unconfirmed
address_street=
verify_sign=AFcWxVudFQq8ZSboMdT0X3W4ahu5PTNt
tax1=0.00
txn_type=invoice_payment
receiver_id=5VPNPEENCQ
payment_fee=
item_number1=
mc_currency=
transaction_subject=
custom=
protection_eligibility=Eligible
quantity1=1
address_country=
payer_status=verified
first_name=
item_name1=Pago+0003
address_name=
mc_gross=58.00
mc_shipping1=0.00
payment_date=10%3a24%3a19+Mar+08%2c+2016+PST
payment_status=Completed
business=
last_name=
address_state=
txn_id=9GE9035442720
mc_fee=7.30
resend=true
payment_type=instant
notify_version=3.8
payer_email=
receiver_email=
address_city=
residence_country=
I'm mainly interested on know if the variable invoice_id= appears on the recurring and subscription payments.
Thank you!
For recurring payments if you passed an invoice ID in the PROFILEREFERENCE parameter of the CreateRecurringPaymentsProfile request it would come back as rp_invoice_id in the IPN.
For subscriptions it would come back as "invoice" if included in the request.
To make the API calls you can send an HTTP request as an NVP string or you can use SOAP.
CreateRecurringPaymentsProfile NVP Reference
CreateRecurringPaymentsProfile SOAP Reference

how to get userId followers and following list with instaSharp?

i use instaSharp api to create an instagram web app
after i get token access i want to see followers and following list of my profile and another people profile
i need some method to Get another user followers and following !
in the official instagram web app you cant see followers and following list (just see amount) , So does this api support it ? How i Can do it ?
this api has a poor document and samples ,
How i can use this method ? instaSharpDoc
thanks
You can see user's followers and followings list with the official Instagram API.
https://instagram.com/developer/endpoints/relationships/ - documentation
https://api.instagram.com/v1/users/{user-id}/follows?access_token=ACCESS-TOKEN - Get the list of users this user follows.
https://api.instagram.com/v1/users/{user-id}/followed-by?access_token=ACCESS-TOKEN - Get the list of users this user is followed by.
You cannot request data from another user, e.g. followers and following, without the user authorization step.
Firstly, you need to redirect the user to an authorization page. After the user inputs his credentials, he will be redirected to a page(redirect_uri value) you have sent in the authorization request, where you will request the access_token to make requests on his account.
There is another option: you can add the username you want to make requests onto your app's Sandbox (require user verification). The username will receive a notification to authorize or revoke the access to your account. After authorizing it, you will be able to make requests on his account.
If you would like to understand more detailed information, please, have a quick look at the documentation about Sandbox at https://www.instagram.com/developer/sandbox/. It will help you clarify your mind and your implementation code.
I hope it helps you.
This solved for me using InstaSharper (without accessToken but using username and password for loggin in):
var following = await api.GetUserFollowingAsync("yourUserName",PaginationParameters.Empty);
var followers = await api.GetUserFollowersAsync("yourUserName", PaginationParameters.Empty);
This is the repository: https://github.com/a-legotin/InstaSharper
Tutorial to get starting: https://www.youtube.com/watch?v=f9leg398KAw
I don't know if this is useful but for me it works:
IResult<InstaUserShortList> followers = await api.GetUserFollowersAsync(userToScrape,
PaginationParameters.MaxPagesToLoad(5));
for (int i = 0; i < followers.Value.Count; i++)
{
Console.WriteLine($"\n\t{followers.Value[i].UserName}\n\t");
}
It gives you back the username of all of the followers of a user (change UserToScrape with the one that you prefer).

How can I set up ASP.NET login to allow the UserName or UserId to be retrieved later on in the session?

I'm trying to create a login system for my website, I've created a custom login.ascx and when the user clicks [ Login ] a div pops up with the contents of login.ascx.
Then after the user enters their credentials, they click on the Login button. They get validated and logged in using this code in the login click function:
if( Membership.ValidateUser( userName.Text, password.Text ) )
{
//Here is where I'm not sure what to do
}
else
{
LoginError.Visible = true;
}
So in the section where I'm not sure what to do, I would like the user to get logged in (Not sure if that means creating an authentication ticket or whatnot). What does is the next step to actually log the user in, I don't want them to get redirected anywhere since they are on the correct page already.
I would also like to be able to retrieve their user name or user id later on for use in my web services. So, for this should I do a Session.Add to create a new session value or is there some other way of storing the data that is preferred?
For authenticating the user,
FormsAuthenatication.SetAuthCookie(username, false/*true if you want to remember the user's login*/);
This logs the user in. You can later use
Page.User.Identity.Name
to retrieve username of the current user and
Page.User.Identity.IsAuthenticated
to check if the user is logged in.
There's no need to store it in Session. Just use:
FormsAuthentication.SetAuthCookie
to send an authentication ticket to the client. Then use HttpContext.Current.User.Identity to retrieve it later.
I find using the membership provider is useful, I would recommend it
Scott Guthrie posted great blog on this
http://weblogs.asp.net/scottgu/archive/2006/05/07/ASP.NET-2.0-Membership-and-Roles-Tutorial-Series.aspx

Categories