Why does Stripe checkout Webhooks send customer_email to null? - stripe-payments

I try to get the customer email after a payment on Checkout Stripe new interface. The JSON posted by stripe Webhook always send customer_email with null value.
The stripe Checkout page ask for customer email so I don't understand why Stripe send back this value to null.
Though, customer value is not null.
{
"id": "evt_1FItv8Kj5elW7ZcvEuY6",
"object": "event",
"api_version": "2019-03-14",
"created": 1568539286,
"data": {
"object": {
"id": "cs_test_123123123",
"object": "checkout.session",
"billing_address_collection": null,
"cancel_url": "https://www.example.fr/canceled",
"client_reference_id": null,
"customer": "cus_FoWzBx2yusHfs9",
"customer_email": null,
"display_items": [
{
"amount": 1000,
"currency": "eur",
"quantity": 1,
"sku": {
"id": "sku_1234567",
"object": "sku",
"active": true,
"attributes": {
"name": "Product test"
},
"created": 1568538814,
"currency": "eur",
"image": null,
"inventory": {
"quantity": null,
"type": "infinite",
"value": null
},
"livemode": false,
"metadata": {
},
"package_dimensions": null,
"price": 1000,
"product": "prod_FoWr00dX3",
"updated": 1568538814
},
"type": "sku"
}
],
"livemode": false,
"locale": null,
"mode": "payment",
"payment_intent": "pi_1FItj5elW70Z2",
"payment_method_types": [
"card"
],
"setup_intent": null,
"submit_type": null,
"subscription": null,
"success_url": "https://www.example.fr/success"
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": null,
"idempotency_key": null
},
"type": "checkout.session.completed"
}

The email the customer entered is actually on the Customer object that the CheckoutSession links to. [0] The customer_email field is something else(it's the field that your code might have set to prefill an email into the Session).
So retrieve the Customer object from the API (cus_FoWzBx2yusHfs9) and check the email field there; or retrieve the Session object and expand the Customer field.
[0] - https://stripe.com/docs/api/customers/object#customer_object-email

Related

Sharepoint REST API - post comment on behalf of another user

There is a way of how to add comments to Sharepoint site using REST API. It is explained here https://beaucameron.com/2021/01/18/add-comments-to-sharepoint-list-items-using-the-rest-api/ for example.
But when I add comment like this, it adds it on behalf of my name - because REST endpoint is accessed using access token, which is linked to my e-mail.
I'd like to migrate comments from one site to the other, and keep original authors.
Is there a way to post comments on behalf of other users?
I tried this POST body:
{
"__metadata": {
"type": "Microsoft.SharePoint.Comments.comment"
},
"text": "Some new comment",
"author": {
"__metadata": {
"type": "SP.Sharing.Principal"
},
"email": "AlexW#OnMicrosoft.com",
"id": 18,
"loginName": "i:0#.f|membership|alexw#onmicrosoft.com",
"name": "Alex Wilber",
"principalType": 1
}
}
But still, comment is posted on behalf of my name. The response is like the following:
{
"d": {
"__metadata": {
"id": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)",
"uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)",
"type": "Microsoft.SharePoint.Comments.comment"
},
"likedBy": {
"__deferred": {
"uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)/likedBy"
}
},
"replies": {
"__deferred": {
"uri": "https://sharepoint.com/_api/web/lists('017dd808-5a37-4d65-89f9-b5ce994554b4')/GetItemById(1)/Comments(15)/replies"
}
},
"author": {
"__metadata": {
"type": "SP.Sharing.Principal"
},
"email": "myName.mySurname#onmicrosoft.com",
"expiration": null,
"id": 12,
"isActive": true,
"isExternal": false,
"jobTitle": null,
"loginName": "i:0#.f|membership|myName.mySurname#onmicrosoft.com",
"name": "myName mySurname",
"principalType": 1,
"userId": null,
"userPrincipalName": null
},
"createdDate": "2022-05-24T08:40:19.0841947Z",
"id": "15",
"isLikedByUser": false,
"isReply": false,
"itemId": 1,
"likeCount": 0,
"listId": "017dd808-5a37-4d65-89f9-b5ce994554b4",
"mentions": null,
"parentId": "0",
"replyCount": 0,
"text": "Some new comment"
}
}
So still, I'm the author of the comment...

Stripe Webhook doesnt capture product data/meta data

I want to use stripe payment link system, The payment method can be Card/Wallet
I dont want to use checkout button system, since the payment isnt dynamic
Once the payment is successful (auto subscription or manual checkout) I need to send the activation code to the users email. The next year when the charge is auto debited from card I need to generate the activation key again and send the same for the next year.
I see there are many events in the Stripe payment webhooks, I have used charge.succeeded event listener and it does send me the object (pasted below).
I have one issue here. If I rely on this charge.succeeded object I find no information on which product the purchase is made. There are many products in my system
The response have user supplied email but there is no way I product details in the charge.succeeded object. I have supplied the metadata info in the payment link page as below. I have also supplied the metadata in products as well as metadata in the every pricings
I use this link - https://buy.stripe.com/test_28o3cn6hC5bgdoIcMM
Test card number: 4242 4242 4242 4242
and any dates and CVV number would work.
Webhook responses are captured here - https://docs.google.com/spreadsheets/d/1RjnFnjHvs9ca8tIPoRiNHFUph_npm5pVK2S15wVllzI/edit?usp=sharing
Any help is greatly appreciated
{
"id": "evt_1KWzCbHpIo9Nhh5aYEv7XlY8",
"object": "event",
"api_version": "2017-12-14",
"created": 1645777861,
"data": {
"object": {
"id": "ch_1KWzCaHpIo9Nhh5atK09dpaO",
"object": "charge",
"amount": 100,
"amount_captured": 100,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_1KWzCaHpIo9Nhh5anEebLs4X",
"billing_details": {
"address": {
"city": null,
"country": "IN",
"line1": null,
"line2": null,
"postal_code": null,
"state": null
},
"email": "te...#email.com",
"name": "CARDNAME",
"phone": null
},
"calculated_statement_descriptor": "XXXXXXXXXXX",
"captured": true,
"created": 1645777860,
"currency": "inr",
"customer": "cus_LDQ2DBhL2VkPOH",
"description": "Subscription creation",
"destination": null,
"dispute": null,
"disputed": false,
"failure_code": null,
"failure_message": null,
"fraud_details": {
},
"invoice": "in_1KWzCYHpIo9Nhh5ammBkFvU1",
"livemode": false,
"metadata": {
},
"on_behalf_of": null,
"order": null,
"outcome": {
"network_status": "approved_by_network",
"reason": null,
"risk_level": "normal",
"risk_score": 58,
"seller_message": "Payment complete.",
"type": "authorized"
},
"paid": true,
"payment_intent": "pi_1KWzCYHpIo9Nhh5aj6Xgl3tS",
"payment_method": "pm_1KWzCXHpIo9Nhh5aADMKyWPc",
"payment_method_details": {
"card": {
"brand": "visa",
"checks": {
"address_line1_check": null,
"address_postal_code_check": null,
"cvc_check": "pass"
},
"country": "US",
"exp_month": 2,
"exp_year": 2022,
"fingerprint": "MxtsbEBU2BmJbOn4",
"funding": "credit",
"installments": null,
"last4": "4242",
"network": "visa",
"three_d_secure": null,
"wallet": null
},
"type": "card"
},
"receipt_email": null,
"receipt_number": null,
"receipt_url": "https://pay.stripe.com/receipts/acct_1BhpF1HpIo9Nhh5a/ch_1KWzCaHpIo9Nhh5atK09dpaO/rcpt_LDQ2FDPK6fwsEyBOISiDCItSv8JeNbl",
"refunded": false,
"refunds": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/charges/ch_1KWzCaHpIo9Nhh5atK09dpaO/refunds"
},
"review": null,
"shipping": null,
"source": null,
"source_transfer": null,
"statement_descriptor": null,
"statement_descriptor_suffix": null,
"status": "succeeded",
"transfer_data": null,
"transfer_group": null
}
},
"livemode": false,
"pending_webhooks": 1,
"request": {
"id": "req_QzrolSFU0OA7D7",
"idempotency_key": "228c5670-85ea-4047-9f9f-9d1e519ffc2c"
},
"type": "charge.succeeded"
}
a Checkout Session will be generated under the hood when your customer opens a Payment Link. Therefore, you should listen to the checkout.session.completed events, and get the product data from the line_items property of the Checkout Session object.
I have had a similar problem when using a webhook solution in Stripe. Although I had defined meta data in the product it was not shipped, i.e. metadata in JSON was empty.
In my case the solution has been to use the meta data of the price instead (which is defined within the product). For this, just click price section on product page on Stripe website...
...and define meta data on the price page.
There is another interesting post https://stackoverflow.com/a/69117489/10849985 showing that it is event-depending if meta data is provided or not, i.e. some events linked to the webhook inlcude it, others not.
For me the issue was that I was merging the price and products objects together which was overwriting the metadata on the product with the empty metadata of the price object.
To fix this I just made sure the metadata was receiving the values from the product obj
const product = await stripe.products.list();
const price = await stripe.prices.list();
const productData = product.data.map((productData, index) => {
return {
...productData,
...price.data[index],
quantity: 1,
addedToCart: false,
metadata: productData.metadata };
});

How to update a subscription (adding a pricing plan) by Stripe in Node.js?

I'm building a web app which sells several products, each product corresponds to a pricing plan. All the payment system is managed by Stripe.
It happens very often that a user has a subscription that contains Product A (i.e., one pricing plan), and then he wants to add Product B (i.e., another pricing plan) to the same subscription. I want to know how to achieve this by APIs of Stripe.
There is a webpage of Stripe to update a subscription (e.g., https://dashboard.stripe.com/test/subscriptions/sub_H4pQGW8nnc80vF/edit where sub_H4pQGW8nnc80vF is the subscription ID). Let's assume this customer already has 1 Verificator in the subscription, and then he wants to add 1 Pretty Formula to the same subscription. I do this update via the website. Here is the log:
Here is the full Request POST body:
{
"items": {
"0": {
"billing_thresholds": "",
"deleted": "false",
"id": "si_H4pQal4ZxGzLbW",
"quantity": "1",
"tax_rates": ""
},
"1": {
"billing_thresholds": "",
"plan": "plan_Gz6i9yPVIjrDPX",
"deleted": "false",
"quantity": "1"
}
},
"off_session": "true",
"prorate": "true",
"cancel_at": "",
"days_until_due": "30",
"default_tax_rates": "",
"collection_method": "send_invoice",
"billing_thresholds": "",
"enable_incomplete_payments": "false",
"invoice_settings": {
"description": "",
"send_hosted_payment_email": "true",
"supported_payment_methods": {
"ach_credit_transfer": "false",
"au_becs_debit": "false",
"bancontact": "false",
"card": "true",
"fpx": "false",
"giropay": "false",
"ideal": "false",
"jp_credit_transfer": "false",
"paper_check": "false",
"sepa_credit_transfer": "false",
"sofort": "false"
},
"custom_fields": "",
"footer": ""
},
"default_payment_method": "",
"default_source": ""
}
Here is the full Response body:
{
"id": "sub_H4pQGW8nnc80vF",
"object": "subscription",
"application_fee_percent": null,
"billing_cycle_anchor": 1586597833,
"billing_thresholds": null,
"cancel_at": null,
"cancel_at_period_end": false,
"canceled_at": null,
"collection_method": "send_invoice",
"created": 1586597833,
"current_period_end": 1589189833,
"current_period_start": 1586597833,
"customer": "5e575130651c5721d808d25b",
"customer_email": "sdtikply#gmail.com",
"customer_name": "Thomas Joseph",
"days_until_due": 30,
"default_payment_method": null,
"default_source": null,
"default_tax_rates": [
],
"discount": null,
"ended_at": null,
"invoice_settings": {
"send_hosted_payment_email": true,
"supported_payment_methods": {
"ach_credit_transfer": false,
"au_becs_debit": false,
"bancontact": false,
"card": true,
"fpx": false,
"giropay": false,
"ideal": false,
"jp_credit_transfer": false,
"paper_check": false,
"sepa_credit_transfer": false,
"sofort": false
}
},
"items": {
"object": "list",
"data": [
{
"id": "si_H4pQal4ZxGzLbW",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1586597833,
"metadata": {
},
"plan": {
"id": "plan_Ga6n9yMYCDnHCu",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 500,
"amount_decimal": "500",
"billing_scheme": "per_unit",
"created": 1579512574,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"name": "Verificator",
"nickname": "Verificator",
"owning_merchant": "acct_1CiOQBEV4K2GahYL",
"owning_merchant_info": "acct_1CiOQBEV4K2GahYL",
"product": "prod_Ga6mVdA8KXyZ8I",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"quantity": 1,
"subscription": "sub_H4pQGW8nnc80vF",
"tax_rates": [
]
},
{
"id": "si_H82ES9BdIKZCNG",
"object": "subscription_item",
"billing_thresholds": null,
"created": 1587337381,
"metadata": {
},
"plan": {
"id": "plan_Gz6i9yPVIjrDPX",
"object": "plan",
"active": true,
"aggregate_usage": null,
"amount": 500,
"amount_decimal": "500",
"billing_scheme": "per_unit",
"created": 1585278262,
"currency": "usd",
"interval": "month",
"interval_count": 1,
"livemode": false,
"metadata": {
},
"name": "Pretty Formula",
"nickname": "Pretty Formula",
"owning_merchant": "acct_1CiOQBEV4K2GahYL",
"owning_merchant_info": "acct_1CiOQBEV4K2GahYL",
"product": "prod_GxqkRFdI08DvyR",
"tiers": null,
"tiers_mode": null,
"transform_usage": null,
"trial_period_days": null,
"usage_type": "licensed"
},
"quantity": 1,
"subscription": "sub_H4pQGW8nnc80vF",
"tax_rates": [
]
}
],
"has_more": false,
"total_count": 2,
"url": "/v1/subscription_items?subscription=sub_H4pQGW8nnc80vF"
},
"latest_invoice": "in_1GWfm1EV4K2GahYLlmtUEISo",
"livemode": false,
"metadata": {
},
"next_pending_invoice_item_invoice": null,
"owning_merchant": "acct_1CiOQBEV4K2GahYL",
"owning_merchant_info": "acct_1CiOQBEV4K2GahYL",
"pause_collection": null,
"pending_invoice_item_interval": null,
"pending_setup_intent": null,
"pending_update": null,
"plan": null,
"quantity": null,
"schedule": null,
"start_date": 1586597833,
"status": "active",
"tax_percent": null,
"trial_end": null,
"trial_start": null
}
So my question is, how can I code in my backend (Node.js) to achieve exactly the same thing?
You just need to use the Update Subscription API and provide the items portion just as you're seeing above:
"items": {
"0": {
"billing_thresholds": "",
"deleted": "false",
"id": "si_H4pQal4ZxGzLbW",
"quantity": "1",
"tax_rates": ""
},
"1": {
"billing_thresholds": "",
"plan": "plan_Gz6i9yPVIjrDPX",
"deleted": "false",
"quantity": "1"
}
},
The first item is the existing Subscription Item (si_), and the second one is the new one you want to add.

How to get customer id from a charge response of stripe?

I am trying to get customer_id of a stripe customer from the response of of charge entity. But response is not providing the customer id in return.
&stripe.Charge JSON: {
"id": "ch_1AxWbTFytruJp2FXW6iuRd1X",
"object": "charge",
"amount": 100,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"balance_transaction": "txn_17JOXKFytruJp2FXS4XNisQd",
"captured": false,
"created": 1504339423,
"currency": "usd",
"customer": null,
"description": "My First Test Charge (created for API docs)",
"destination": null,
"dispute": null,
"failure_code": null,
"failure_message": null,
"fraud_details": {
},
"invoice": null,
"livemode": false,
"metadata": {
},
"on_behalf_of": null,
"order": null,
"outcome": null,
"paid": true,
"receipt_email": null,
"receipt_number": null,
"refunded": false,
"refunds": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/charges/ch_1AxWbTFytruJp2FXW6iuRd1X/refunds"
},
"review": null,
"shipping": null,
"source": {
"id": "card_1AxWPmFytruJp2FXw4m0V0fN",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": "10001",
"address_zip_check": "unchecked",
"brand": "Visa",
"country": "US",
"customer": null,
"cvc_check": "unchecked",
"dynamic_last4": null,
"exp_month": 4,
"exp_year": 2024,
"fingerprint": "sNtyd9sZ2vA6o4IM",
"funding": "credit",
"last4": "4242",
"metadata": {
},
"name": "Mandeep",
"tokenization_method": null
},
"source_transfer": null,
"statement_descriptor": null,
"status": "succeeded",
"transfer_group": null
}
But it has a customer field inside the object which is null. Can anyone please tell me why am I getting this null?
What I am trying to do is to make a system where customer can book anonymously on site and while creating the booking the customer gets registered and charged for the total amount of the booking. I need to keep track of the customer's stripe account id and card id. So the problem is if I am creating a customer then I am not able to get its card id but when I am charging the customer then I am not able to get the customer id.
Customer Response:
&stripe.Customer JSON: {
"id": "cus_BKAxGZre2HCNIU",
"object": "customer",
"account_balance": 0,
"created": 1504339424,
"currency": "usd",
"default_source": null,
"delinquent": false,
"description": null,
"discount": null,
"email": null,
"livemode": false,
"metadata": {
},
"shipping": null,
"sources": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_BKAxGZre2HCNIU/sources"
},
"subscriptions": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_BKAxGZre2HCNIU/subscriptions"
}
}
When you create a charge using only the credit card token, no Stripe customer is created, you only create a payment with no associated customer.
So it's normal that you the API returns customer: null.
Instead of charging a credit card, I think you should charge a new customer.
In your backend code, you could handle the payment in 2 steps:
STEP 1: create a new customer, passing the credit card token to store
the customer's card
STEP 2: charge the customer, using the customer ID returned by
STEP 1 API call.
Doing this, you charge the customer with the credit card that is stored in customer's data.
For more details, check here: https://stripe.com/docs/quickstart#saving-card-information
Does it make sense?
You can access card_id while creating new customer using following code (in Golang):
for _, data := range customer.Sources.Values{
card_id = data.ID
}
fmt.Println(card_id)
I spend almost 1 day to figure it out. Actually in customer structure(under stripe package) there are some fields which are having embedded types and such fields are further connected to some other structure in different files. So there is hierarchy to access structure fields like above.
Hope this will solve your problem.
Thanks!

Get Organization ID or domain from Azure AD Graph

We're developing a multi-tenant SSO integration with Office 365 using the new OpenID implementation.
Once the access token has been retrieved, we call https://graph.windows.net/me?api-version=1.21-preview to get the user's profile information which gives something like the below - great.
{
"odata.metadata": "https:\/\/graph.windows.net\/myorganization\/$metadata#directoryObjects\/Microsoft.WindowsAzure.ActiveDirectory.User\/#Element",
"odata.type": "Microsoft.WindowsAzure.ActiveDirectory.User",
"objectType": "User",
"objectId": "GUID",
"accountEnabled": true,
"assignedLicenses": [
],
"assignedPlans": [
],
"city": null,
"country": null,
"department": null,
"dirSyncEnabled": null,
"displayName": "Tester A",
"facsimileTelephoneNumber": null,
"givenName": "Test",
"immutableId": null,
"jobTitle": null,
"lastDirSyncTime": null,
"mail": null,
"mailNickname": "tester-a",
"mobile": null,
"otherMails": [
],
"passwordPolicies": "None",
"passwordProfile": null,
"physicalDeliveryOfficeName": null,
"postalCode": null,
"preferredLanguage": null,
"provisionedPlans": [
],
"provisioningErrors": [
],
"proxyAddresses": [
],
"state": null,
"streetAddress": null,
"surname": "A",
"telephoneNumber": null,
"usageLocation": null,
"userPrincipalName": "tester-a#test.onmicrosoft.com",
"userType": "Member"
}
However, it doesn't seem to return any identifier or specific domain for the organization - other than the domain contained in the userPrincipalName field. Is there a better way to identify the organization (considering the organization may update test.onmicrosoft.com to a custom domain of test.microsoft.com)?
Indeed. Use the tenantDetails API (https://graph.windows.net/{tenantDomain}/tenantDetails?api-version={version}), to get the display name of the directory and all verified domains associated with it. Documented here: http://msdn.microsoft.com/en-us/library/azure/hh974467.aspx.
Below is the trimmed output for my tenant.
Hope this helps.
{
"odata.metadata": "https://graph.windows.net/dushyantgill.com/$metadata#directoryObjects/Microsoft.WindowsAzure.ActiveDirectory.TenantDetail",
"value": [
{
"odata.type": "Microsoft.WindowsAzure.ActiveDirectory.TenantDetail",
"objectType": "Company",
"objectId": "62e173e9-301e-423e-bcd4-29121ec1aa24",
"assignedPlans": [
{
"assignedTimestamp": "2013-09-17T01:01:58Z",
"capabilityStatus": "Enabled",
"service": "SharePoint",
"servicePlanId": "a1f3d0a8-84c0-4ae0-bae4-685917b8ab48"
} [SNIP]
],
"city": "Redmond",
"companyLastDirSyncTime": "2014-04-20T17:42:58Z",
"country": null,
"countryLetterCode": "US",
"dirSyncEnabled": true,
"displayName": "dushyantgill",
"marketingNotificationEmails": [],
"postalCode": "98052",
"preferredLanguage": "en",
"provisionedPlans": [
{
"capabilityStatus": "Enabled",
"provisioningStatus": "Success",
"service": "exchange"
}[SNIP]
],
"provisioningErrors": [],
"state": "WA",
"street": "[SNIP]",
"technicalNotificationMails": [
"[SNIP]"
],
"telephoneNumber": null,
"tenantType": null,
"verifiedDomains": [
{
"capabilities": "Email, OfficeCommunicationsOnline",
"default": false,
"id": "0005000080186A52",
"initial": false,
"name": "dushyantgill.mail.onmicrosoft.com",
"type": "Managed"
},
{
"capabilities": "Email, OfficeCommunicationsOnline",
"default": false,
"id": "00057FFE803C0EDA",
"initial": false,
"name": "dushyantgill.org",
"type": "Federated"
},
{
"capabilities": "Email, OfficeCommunicationsOnline",
"default": true,
"id": "00053FFF80232F54",
"initial": false,
"name": "dushyantgill.com",
"type": "Managed"
}[SNIP]
]
}
]
}

Resources