Stripe Address Element: how to get the value of the Name field? - stripe-payments

The address is missing the name related values even when the addressElement is rendering the Name field even when using the same code as mentioned in the Stripe documentation here
addressElement.on('change', (event) => {
if (event.complete){
// Extract potentially complete address
const address = event.value.address;
}
})
returns this
{
"line1": "",
"line2": null,
"city": "",
"country": "US",
"postal_code": "",
"state": ""
}
It seems that the workaround to get the value could look like
document.getElementById('Field-nameInput').value
But doesn't look graceful.
Where is the value of the Name field? How do I get it? Am I missing something obvious here?

This is available as value.name in the change event, or firstName and lastName if you use the split display for name. From the docs for value (reference):
An object containing the current address information. The firstName
and lastName properties only appear if the display.name option is set
to split. The phone property only appears if the fields.phone option
is set to always.

Related

Adding ACL for nested field object in JSON schema object

I am working on specify ACL fields for fields inside objects. I have the validator to check for permission to edit a specific field. For example, the schema looks like this:
"basic_info": {
"properties": {
"cadi_id": {
...
},
"analysis_keywords": {
...
},
"abstract": {
"type": "string",
"title": "Abstract",
"acl": {
"users": ["test#test.org", "test1#test.org"]
}
},
"ana_notes": {
...
},
"conclusion": {
...
}
},
"title": "Basic Information",
"type": "object",
"id": "basic_info",
"required": ["cadi_id"]
}
I have the abstract field with acl. It works fine when the user(not in acl) is editing the abstract field and the validation error is thrown when the user is not in acl.
The problem comes when user(not in acl) is editing other field like conclusion and have the same ValidationError.
When editing any field in basic_info, for example conclusion field, the whole basic_info object is processed in the validator beacuse it's the parent field and now user should be able to edit the conclusion field because there is no acl set. but it gives the ValidationError because we also receive the abstract (which is unchanged) in the basic_info and it goes to validate method and since the user is not in acl it gives ValidationError .
Please let me know what I am missing here to let the user(not in acl) to edit the non acl field?
I tried to get the previous value from the db and check if the controlled field is edited by user or not, but it doesn't seems efficient for this use case and I want to know if there is any native way to do the field level validation. I could not find anything in the docs.

What is the correct python query to pull phone number type in Twilio Lookup api and why?

Based on Twilio Lookup docs https://www.twilio.com/docs/lookup/api?code-sample=code-carrier-lookup-with-e164-formatted-number&code-language=Python&code-sdk-version=6.x
I assume the following:
phone_number = client.lookups.phone_numbers('+19234567890').fetch(type=['carrier'])
returns:
{
"caller_name": null,
"carrier": {
"error_code": null,
"mobile_country_code": "123",
"mobile_network_code": "987",
"name": "verizon",
"type": "mobile"
},
"country_code": "US",
"national_format": "(923) 456-7890",
"phone_number": "+19234567890",
"add_ons": null,
"url": "https://lookups.twilio.com/v1/PhoneNumbers/+19234567890?Type=carrier"
}
Why does
print(phone_number['carrier']['type'])
return an error TypeError: 'PhoneNumberInstance' object is not subscriptable
But:
print(phone_number.carrier['type'])
Correctly return "mobile"
Twilio developer evangelist here.
The docs show the full JSON response that the API returns. However we built the libraries to return objects that you can call regular methods on. So, the phone_number object returned here:
phone_number = client.lookups.phone_numbers('+19234567890').fetch(type=['carrier'])
has methods defined, based on our API definitions, for things like carrier, country_code, and national_format.
On the other hand, I don't think we necessarily have a definition for that carrier object, so it is returned as a dictionary. Thus, to look into fields on the carrier you need to use the index ([]) operator.
You can check the definition of the phone_number object on GitHub here.

How to populate DocuSign Name field with something other than Sender name?

I'm using DocuSignAPI SDK to send envelopes. I have a few templates defined and they use a Custom Field called MemberFullName.
The field is of type Name, FullName.
For some templates I want MemberFullName map to a Signer's name, but sometimes I want to map another name to it.
My assumption was if I don't map anything to MemberFullName, then Signer's name will be used. But if I add "fullNameTabs" for MemberFullName, then it will be mapped.
Signer sgnr = new Signer()
{
RoleName = "Someone other than Member",
RecipientId = "1",
Name = "Bob Signer",
Email = "bobsemailaddress#yahoo.com"
};
sgnr.Tabs.FullNameTabs = new List<FullName>();
sgnr.Tabs.FullNameTabs.Add(new FullName() { TabLabel = "MemberFullName", Name = "Joe Smith" });
But MemberFullName is still mapped to Signer name in the resulting document.
How can I map a NON-SIGNER name to a field of type "Name"?
I know I can create a different field of type TEXT and map "Joe Smith" to it, but I wanted to reuse the "MemberFullName" field in both situations.
I apologize as I may not be using correct "docusign terminology" for things.
You will not be able to set the value of FullName tab manually. See this answer
for more information.

Saving a Person or Group field using REST

Does anyone know how to save a Person field using REST?
I have tried the following and it works:
{
"__metadata": { "type": "SP.Data.SomeListListItem" } ,
"MyPersonFieldId" : 1
}
But this only works if you know the ID. I don't have that! How can I get it? I have the key which is i.0#w|domain\userName.
I tried the following and it doesnt work either:
{
"__metadata": { "type": "SP.Data.SomeListListItem" } ,
"MyPersonField" : { "__metadata": { "type": "SP.Data.UserInfoItem" }, "Name": "i.0#w|domain\userName" }
}
Any ideas?? Thanks!
I haven't done this with a Person field, but I did do something similar with a managed metadata field. I basically had to pass in additional information as an object to create the value in the field.
See if passing in the ID of the user along with the name works. I'm about to try this myself as I have the same need.
{
"MyPersonField": { "Name": "i.0#w|domain\userName", "ID": 1 }
}
EDIT: Ok, updating this field is easier than I thought. I was able to perform the update by simply passing in the ID of the user to the Id field:
{
"MyPersonFieldId": 1
}
This means the user should already be in the site collection, so if the user doesn't exist the request will fail.
Use the below code to get Current User ID to save user under People and group column. People column name is Requestor. But to save user we have to specify column name as RequestorId
var userid = _spPageContextInfo.userId; // To get current user ID
var itemProperties={'Title':vTitle,'RequestorId':userid};
The thing is that User information is a lookup field thereby MyPersonField does not exist on your SharePoint list if you use an OData endpoint, I really don't know how to save data but same problem happened to me when I tried to read a user.
for example {server}/{api}/list/getbytitle('mylist')/items does not return MyPersonField instead return MyPersonFieldId.
But if we use:
{server}/{api}/list/getbytitle('mylist')/items/?$select=*,MyPersonField/Name&$expand=MyPersonField
We are able to work with MyPersonField lookup values.

Automatic document updates in couchdb

I have 10,000+ couchdb documents, each having (simplified) format like -
{
"First Name" : "John",
"Last Name" : "Doe"
}
I want to add another field to this document, which is e-mail, so that document now looks like -
{
"First Name" : "John",
"Last Name" : "Doe",
"e-mail" : ""
}
I understand that I can easily update this document by inserting a new JSON, in new format.
But my question is how can I add new field automatically to "all 10,000+" docs that I have existing in the DB? Do I need to write my own script to read each doc and update each one of them individually? Or is there a simpler way?
If you use views to access your data, you can modify the view without having to modify the documents. Just emit an email value with a default of "".
Assuming the above is no good, use a view to show you which documents need upgrading.
function(doc) {
// views.email_upgrade.map
if(! ('e-mail' in doc)) {
var key = [doc["Last Name"], doc["First Name"]];
emit(key, {_id:doc._id, _rev:doc._rev});
}
Query /db/_design/foo/_view/email_upgrade?include_docs=true. You can add a &limit=N property to help. Query. The doc value in each row is a document that needs to upgrade. You can send them back with POST /db/_bulk_docs. Loop until you have 0 rows. Once you have 0 rows, add a check to your validate_doc_update function.

Resources