Apple Pay on web using stripe.js, populating the popup - applepay

I am testing the Apple Pay JS, I have it working completely. However, I would like to populate the confirmation popup (the one that asks to accept the purchase) with some other fields, like user's name or address. The documentation says it can be done, but there are no examples. Here is the code I am referring to:
var request = {
countryCode: 'US',
currencyCode: 'USD',
supportedNetworks: ['visa', 'masterCard'],
merchantCapabilities: ['supports3DS'],
total: { label: 'Your Label', amount: '10.00' },
}
var session = new ApplePaySession(1, request);

This can most certainly be done.
The PaymentRequest object allows you to include a shippingContact object that is a shipping dictionary. The available fields are listed on their PaymentContact page.
So your PaymentRequest will look like
var request = {
countryCode: 'US',
currencyCode: 'USD',
supportedNetworks: ['visa', 'masterCard'],
merchantCapabilities: ['supports3DS'],
total: { label: 'Your Label', amount: '10.00' },
shippingContact: {
givenName: 'Martin', familyName: 'StackOverflow',
addressLines: ['123 Main St', 'Apt: 5'],
locality: 'Whoville',
administrativeArea: 'FL',
postalCode: '43210',
country: 'US'
}
}
var session = new ApplePaySession(1, request);
When you pass this information to the PaymentRequest, that address will show up in the Paysheet. It will not add the contact to their list of contacts, and they can still overwrite it with their own contacts, but that address will be what shows in the Paysheet by default.

As far as I'm aware you cannot write contact information to the Apple Pay sheet using the JavaScript API, only read the values the user has entered back. Pre-propulated values come from the phone from details entered for the user's previous Apple Pay sessions, whether on the web or in apps, are then saved into Wallet by the device.
You can read some of the contact details from the event passed to the onshippingcontactselected function, with everything being returned in the event passed to the onpaymentauthorized function.

Related

Strapi send email to all administrators

Let's say we have a contact form connected with Strapi backend. Every form submit creates a new model entry and everything's fine except we need to notify administrators about new form submission.
So in api/message/model.js we add a custom lifecycle method:
module.exports = {
lifecycles: {
async afterCreate(result, data) {
await strapi.plugins["email"].services.email.send({
to: [/* Here a list of administrator email addresses should be. How to get it? */],
from: "robot#strapi.io",
subject: "New message from contact form",
text: `
Yay! We've got a new message.
User's name: ${result.name}.
Phone: ${result.phone}.
Email: ${result.email}.
Message: ${result.text}.
You can also check it out in Messages section of admin area.
`,
});
},
},
};
But I don't understand how to get administrator email addresses.
I've tried to query admins data like
console.log(
strapi.query("user"),
strapi.query("administrator"),
strapi.query("strapi_administrator")
);
But it does not work.
Ok, I got it.
The model name is strapi::user. So the whole lifecycle hook may look like
module.exports = {
lifecycles: {
async afterCreate(result, data) {
const administrators = await strapi.query("strapi::user").find({
isActive: true,
blocked: false,
"roles.code": "strapi-super-admin",
});
const emails = administrators.map((a) => a.email);
await strapi.plugins["email"].services.email.send({
to: emails,
from: "robot#strapi.io",
subject: "New message from contact form",
text: `
Yay! We've got a new message.
User's name: ${result.name}.
Phone: ${result.phone}.
Email: ${result.email}.
Message: ${result.text}.
You can also check it out in Messages section of admin area.
`,
});
},
},
};

Gmail API for managing multiple signatures

Google recently released an update to Gmail to bring support for multiple signatures. Ref: https://support.google.com/mail/answer/8395.
I do not see anything in the API documentation at https://developers.google.com/gmail/api/v1/reference that talks about how to manage those multiple signatures. How can I:
create a new signature
update a specific existing signature
associate a signature to an email address - both the "for new emails use" and "on reply/forward use"
Is there any documentation on this?
It is a bit hidden, the signature(s) need to be created with Users.settings.sendAs: create or update
As specified for the resource, signature is one of the parameters that can be modified and you do not need to create a new alias, but can also apply this method to your primaary email:
Settings associated with a send-as alias, which can be either the
primary login address associated with the account or a custom "from"
address.
Important: Access restricted to service accounts that have been delegated
Sample with Apps Script:
function createAlias() {
var alias = 'your primary email';
var signature = 'Your signature';
var service = getOAuthService();
service.reset();
if (service.hasAccess()) {
var url = 'https://www.googleapis.com/gmail/v1/users/me/settings/sendAs'
var headers ={
"Authorization": 'Bearer ' + service.getAccessToken(),
"Accept":"application/json",
"Content-Type":"application/json",
};
var resource ={
sendAsEmail: alias,
signature: signature,
};
var options = {
'headers': headers,
'method': 'POST',
'payload':JSON.stringify(resource),
'muteHttpExceptions': true
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
}
}
Necessary scope:
https://www.googleapis.com/auth/gmail.settings.sharing

User and Bot messages appear on same side of chat container

I built a QnA Maker and integrated it via Direct Line in my Website using BotFramework-WebChat for styling.
Messages of the user and the bot are appearing at the same side of the chat container. I can't figure why.
This is how it currently looks like:
This is the code I'm using:
<script>
const styleSet = window.WebChat.createStyleSet({
bubbleFromUserBackground: 'rgba(227, 227, 227, .1)',
hideUploadButton: true,
botAvatarInitials: 'WD',
sendTypingIndicator: true,
userAvatarInitials: 'you'
});
styleSet.textContent = Object.assign(
{},
styleSet.textContent,
{
fontFamily: '\'Lato\', sans-serif'
}
);
window.WebChat.renderWebChat(
{
directLine: window.WebChat.createDirectLine({
token: 'xxxxxx'
}),
styleSet,
userID: 'qna-homepage-bot',
username: 'Web Chat User',
locale: 'en-US',
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
</script>
I wasn't able to reproduce this, but I suspect you are setting your user ID to the same value as the bot ID. When Web Chat receives an activity, it sets the role property in the activity's from attribute based on the ID (you can take a look at the source code here). Web Chat then uses the role to determine how the activity is styled. If the bot id equals the user id, Web Chat will confuse the role attribute and apply the wrong CSS stylings. Try changing the userID value in the render Web Chat options to something else.
Note, the userID value should be unique for each user; otherwise, every conversation will share the same user state.
Hope this helps!

Possible Parse bug in matchesKeyInQuery

If a post in my Parse database is liked, I want to send a push to the author via cloud code.
To be able to send pushes to specific users, all installations store the objectId of the current user. To find the author of the liked post, I use the query
var userWhosePostWasLikedQuery = new Parse.Query(Parse.Installation);
userWhosePostWasLikedQuery.equalTo(kClassInstallationKeyCurrentUserId, userWhosePostWasLiked.id);
This works fine: A single push is sent to the author.
Now I want to send this push only if the author has such pushes enabled. Thus each user stores a push settings array with enable flags for different pushes.
I use now another query for all users who have such pushes enabled:
const User = Parse.Object.extend(kClassUser);
var pushEnabledUserQuery = new Parse.Query(User);
pushEnabledUserQuery.equalTo(kClassUserKeyPushSettings, kPushNotificationTypePostLiked);
This query correctly returns all users who have such pushes enabled.
Eventually, I want to constrain the query for installations with the author as current user, by this query for users who have pushes enabled. This is done in the following way:
var userWhosePostWasLikedQuery = new Parse.Query(Parse.Installation);
userWhosePostWasLikedQuery.equalTo(kClassInstallationKeyCurrentUserId, userWhosePostWasLiked.id);
userWhosePostWasLikedQuery.matchesKeyInQuery(kClassInstallationKeyCurrentUserId, kPFObjectId, pushEnabledUserQuery);
Since the old query without the 3rd line returns 1 user, the new query with the additional constraint (matchesKeyInQuery) should return the same user, since the author has pushes enabled.
But it returns 2 users, the author and another user who liked the post.
To my understanding, this looks like a Parse bug, since all constraints to a query are ANDed.
Any ideas, maybe for a workaround?
your var "kPFObjectId" should be change to "user".
the default parse Installation come with the pointer named "user" and not "kPFObjectId".
I can tell you that Im using the same method ("matchesKeyInQuery") and it is working well:
Parse.Cloud.define("sendPushForChat", function(request, response) {
var userId = request.params.userId;
var groupId = request.params.groupId;
var query = new Parse.Query('RecentActivity');
query.equalTo('groupId',groupId);
query.include('user');
query.notEqualTo('user', {__type: "Pointer", className: "_User", objectId: userId});
var queryInstallation = new Parse.Query(Parse.Installation);
queryInstallation.matchesKeyInQuery('user', 'user', query);
var message = request.params.messageContent;
Parse.Push.send({
where: queryInstallation,
data: {
alert: message,
badge: "Increment",
title: "מה נשמע?"
}
}, {
success: function() {
console.log("Push for chat was successful");
response.success('Push for chat was successful');
},
error: function(error) {
console.error(error);
response.error('error');
},
useMasterKey:true,
});
})

Mojo SDK retrieve all contacts

I'm playing with the Mojo SDK and I want to get all contacts.
this.controller.serviceRequest('palm://com.palm.contacts/crud', {
method: 'listContacts',
parameters: {
limit: 100
},
onSuccess: this.handleListResponse.bind(this),
onFailure: function(errResp){
Mojo.Log.info(errResp.errorText)
}.bind(this),
onerror: function(errResp){
Mojo.Log.info(errResp.errorText)
}.bind(this)
});
This is what I have right now, but I don't get anything back. And Mojo.Log.info doesn't seem to work. Any suggestions?
Thanks
I'm also fairly new at PRE development but here is what I think the issue is.
The error that comes back is "Account Not Found". You need to add accountId: as a parameter to the service request.
That account id, according to the documentation, is a Synergy account and needs to be created for your application. Click here for reference about the accountId and createAccount methods

Resources