I have implemented PayPal on my site. When user choose service to pay he is redirected to pay pal where he commit payment and in the end he is redirected back to my site.
Here I mix IPN and PDT. After payment I receive IPN message and save all variables in database.
When user is back to the site here I get his TXN_ID and UserID (from session) and store it in database.
I read somewhere that it is bad to mix pdt and ipn. Is there any better way to save IPN variables with UserID? Can I somehow send UserId to pay pal and get it with IPN message later when user finish payment?
I'm sorry I have to reopen question. I added 'invoice' field to send UserID to pay pal. But when I try to pay next time with same user ID I am redirected to pay pal page and I receive this error message:
This invoice has already been paid. For more information, please
contact the merchant.
It seams that invoice is not a good option to send user id to pay pal.
I tried to put user ID in "custom" field.
<input name="custom" type="hidden" id="custom" value="<%= UserInfo.UserID%>">
But all I get in IPN message is:
custom=%3C%25%3D+UserInfo.UserID%25%3E
The way I do it is to use the invoice field. This is a field you can send PayPal and they will send it back in the response. This is how I identify transactions coming back from PayPal.
And in my case I don't process both PDT and IPN messages. I process only the one that hits me first. When the second message (PDT or IPN) arrives I check that I have already processed that transaction and I simply discard it.
Also, please don't forget that you need to verify that the messages came from PayPal. Once you get the PDT or IPN message you need to post back to PayPal with your unique Auth_id and the tx token they sent in the original message. You should not rely on any field from the original message.
Once PayPal receives your confirmation request, it will send you a second message with the transaction details. This is the one you should rely on.
I don't see any benefit on processing both PDT and IPN messages for the same transaction. Having said that I do encourage you to implement both, because none of them are guaranteed to reach you.
Edit to include how to pass the invoice to PayPal
To pass the invoice to PayPal, just create a field like:
<input type="hidden" name="invoice" value=$uniquevaluecreatedbyyourapplication>
The unique id could be your user id.
The post to PayPal will be something like
paypal/or/sandbox/address?all the other fields&invoice=123456
Paypal will send back the invoice in the PDT and IPN messages.
Edit - non-unique invoice id number
I did further research and you can configure PayPal to accept multiple transactions for the same invoice id or to accept only one transaction per invoice id. See below the information straight from PayPal's website:
Blocking Accidental Payments
You can choose whether to accept payments with the same Invoice ID or
to block payments when the Invoice ID was already used.
When you receive payments from buyers, you can include an optional
Invoice ID field to track payments; buyers will not see this ID. A
buyer's Invoice ID must be unique for each transaction. If PayPal
receives a payment with an Invoice ID that was used for another
payment, PayPal will not accept the transaction.
To set the options for blocking this type of payment:
Log in to your PayPal account at https://www.paypal.com.
The My Account Overview page opens.
Click the Profile subtab.
The Profile Summary page opens.
In the Selling Preferences column, click the Payment Receiving
Preferences link.
The Payment Receiving Preferences page opens.
Scroll down the page to the Block accidental payments section as shown
below.
Select one of the following options:
Yes, block multiple payments per invoice ID – Do not accept more
than one payment per invoice. This option prevents duplicate payments
that you must refund.
No, allow multiple payments per invoice ID – Do not limit the number
of payments received for an invoice. Choosing this option might result
in duplicate payments that require a refund.
Scroll to the bottom of the page and click the Save button.
Another option would be to create your invoice id with user id + a random number. This would make it unique.
See below a sample code to get unique invoice numbers.
var r = Math.floor(Math.random()*100000);
var invoice = userid + "-" + r;
You could also use date & time instead of a random number.
var d = new Date();
var invoice = userid + "-" + d;
And in the response back from PayPal, you just discard what comes after the dash.
I hope this helps.
Related
Is there a field within the Marketo API field list that shows the status for each email address listed in a program? Like can it show ("Opened", "Bounced") etc etc. I know there is a field for bounced but I am curious about open rate etc.
How does the Unsubscribe status work with Marketo? The documentation is unclear in that it shows that it is system generated (with no explanation of HOW) and then there is an Unsubscribe Status field that is supposed to populate the email address if they personally unsubscribed? I had 2,000 contacts populate as unsubscribed but 0 populate in the Unsubscribe Status field. This is a bit worrisome given again NO documentation whatsoever in how it populates.
I tried utilizing all fields provided from Marketo on their documentation site but I feel like there has to be a field that shows the status of each email - otherwise how does it show on the dashboard when you log-in? https://developers.marketo.com/rest-api/lead-database/fields/list-of-standard-fields/
I have 2 states : invoice state keep detail of invoice such as invoice no , amount , vat , payment batch (reference to payment state) etc. and payment state keep detail of payment such as payment batch , items of invoice. What's the best practices to implement flow when invoice paid ?
create updatePaymentFlow for update status to "PAID" in payment state and create updateInoviceFlow for update status to "PAID" in invoice state and then loop of all invoice in payment batch to call updateInoviceFlow.
create only flow updatePaymentAndInvoiceFlow for update both payment state and invoice state.
If there is an example that would be great.
see picture
Looking at the picture I understand that a Payment is dependent on Invoice state, and an Invoice state will have its own status - PAID/UNPAID, and Payment state will have its own status field - PAID/UNPAID. Payment state status will be PAID once all the invoice's have PAID status. I think what is the best way to implement this scenario is what your question is.
I would say have Invoice state as a StatePointer in your Payment state. In this way you can have a flow which will take care of updating the Invoice status. And you can have other flow which takes care of updating your Payment status. In this way, invoice status can be updated independently of Payment. Also having referencing the invoice as StatePointer(Linear Pointer) will always give you the latest updated state in Payment.
I am integrating the Stripe payment gateway with a subscription-based product website in ASP.NET Core 3.1.
I have a Subscription table in the SQL Server database. It has expiration_date (datetime) and is_active (bit) columns.
When the user subscribes to a product with a recurring price (per month), I add a current date + 1 month in the expiration_date column. I also insert 1 in is_active column to indicate that the subscription is active.
Once the first month of subscription has passed, I want the value of is_active flag of this subscription to become 0 in the database. Once the user has paid for the next month, the Current Period will update in stripe subscription and the value of is_active flag is to become 1 again.
For this purpose, I should use Stripe WebHooks. I want to get notified through webhook that a subscription period has ended. I am confused because, as per my understanding, webhook events for customer.subscription and price do not define something that gets triggered when the current period of subscription ends.
The image attached below indicates the current period and date of the next invoice. From documentation I have come to know that upcoming invoice events can be used. But I am not understanding how a webhook can be used with the upcoming invoice.
So, my questions are that which event fires at the end of the final day of one month of the subscription period and which one is fired when a new period is defined?
See https://stripe.com/docs/billing/invoices/subscription#subscription-renewal and https://stripe.com/docs/billing/subscriptions/webhooks#tracking.
When a subscription period ends, an invoice is created(invoice.created) to charge for the upcoming one. So when the cycle ends, you get a customer.subscription.updated event (because current_period_start and current_period_end are updated to the new period) and also an invoice.created event for the invoice that gets created to charge for this new period.
The way I would do it is
listen to the invoice.created event
when handling it, check that the billing_reason is subscription_cycle to differentiate from invoices created for other reasons https://stripe.com/docs/api/invoices/object#invoice_object-billing_reason
retrive the referenced subscription from the invoice(https://stripe.com/docs/api/subscriptions/retrieve) and look at the current_period_[start|end] fields, which is the information you're looking for.
You could also listen to customer.subscription.updated and check if the reason for it updating is the billing period changing(by looking for current_period_start in the previous_attributes of the Event ); or do the same as above but via invoice.paid instead of invoice.created if you only care to update your system when a successful payment is made(thats what the https://stripe.com/docs/billing/subscriptions/webhooks#tracking approach does)
I need to send a cart status update based on an offline activity. My customers will add items to their cart online via the website but the final checkout and purchase happen offline.
Here is my question: In the example below, a checkout step is updated. Does the client_id provided in this step have to match the original client_id used when the web user started their cart originally?
Measuring Checkout Options
v=1 // Version.
&tid=UA-XXXXX-Y // Tracking ID / Property ID.
**&cid=555 // Anonymous Client ID.**
&t=event // Event hit type
&ec=Checkout // Event Category. Required.
&ea=Option // Event Action. Required.
&pa=checkout_option // Product action (checkout_option).
&cos=2 // Checkout step.
&col=FedEx // Checkout step option.
Client ID is how Google Analytics tracks each individual user throughout their multiple sessions. So, yes- if you want that payload to be associated with the same user, then the CID will need to match- otherwise you'll be artificially inflating your user count (as well as severing the contextual data from that user).
You can parse the cookie that GA stores in the browser to obtain the CID and then fill it there. Not sure what language you're writing in, but there are plenty of snippets out there for parsing the GA cookie. You could also store the CID when it is initially generated in your own session data to be used later while offline. For example:
ga(function(tracker) {
var clientId = tracker.get('clientId');
console.log(clientId);
});
You could also provide your own CID from the start that you generate yourself and tell Google Analytics to use. This might be overkill for your situation, but I wanted to mention it as an option.
I am trying to track the number of email opens of a mailing.
This mailing is not personalised, so each receiver will get exactly the same email contents.
So far I have found out that I can add a tracking pixel in the mailing, which will send data to GA that a user opened the mail (images were loaded).
Example code:
<img src=”http://www.google-analytics.com/collect?v=1&tid=UA-XXXXXX-X
&cid=EmailOpenTest&t=event&ec=email&ea=open&el=EmailOpenTest
&cs=newsletter&cm=email&cn=Email&cm1=1″ />
'tid' will be our custom tracking ID.
This all works, as when this link is opened the total number of hits increases.
But my question relates to parameter 'cid'. For testing purposes, I have set this here to "EmailOpenTest". But this should be a random/unique ID per user actually. But as the mailing is not personalised, I wonder if it would be possible to track individual users?
Does this mean I have to include javascript in the mail? Would that even work in all email clients? Or are there other options?
All suggestions are welcome.
Assumption: you are using a mail client like Mail Chimp
Assign a unique id to every email on the email list. lets say this unique id is uid
Create a custom dimension in GA, lets name it as Client Mail Id with index say 1
Create the same pixel just like you have created above in the OP.
Add a custom Dimension in the hit as
http://www.google-analytics.com/collect?v=1&tid=UA-XXXXXX-X
&cid=EmailOpenTest&t=event&ec=email&ea=open&el=EmailOpenTest
&cs=newsletter&cm=email&cn=Email&cm1=1&cd1=uid
In place of uid, you actually need to pass the mail list unique id for that email
How it will work
Once the user sends this hit, your unique id will be recorded in custom dimension 1.
Generate a custom report in GA with event category=email & event action=open and add a dimension custom dimension 1.
All the id's displayed there have actually opened the email ;)
PS: It's tried and tested, so won't cause any issue. Also if you don't want to use custom dimensions, you can also send this id in event label or event value
PPS: In any mail client, getting unique value for that email is pretty easy. You can actiually use its position number or add another column for the unique id, then grab that id win the template
The cid is the clientId, an identifier that is used to aggregate pageviews into sessions, and sessions into unique users.
The way to use that in email-tracking would be to capture the client id when a user subscribes to your newsletter and then insert it into the email links. Since your mails are not personalized this will not work.
If you use a random ID you will not be able to link the request from the mail to an existing user. So one way to deal with the problem would be to ignore it - using a constant userId would still give you an event count (the unique events metric might be a little of if users click the link multiple times within a session lifetime).
If for some reason you absolutely need to track these as different users you can set up a redirect - do not send data to ga directly from your mail, instead call a script on your server that inserts a random clientId and then sends the data to Google.