Send Shipping Address details with Stripe Custom Checkout - stripe-payments

I have a stripe checkout that's using the now unsupported "data-shipping-address="true"" parameter. This works as expected when using the simple stripe checkout with the following code:
<script
src="https://checkout.stripe.com/checkout.js"
class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="1000"
data-currency="gbp"
data-allow-remember-me="true"
data-shipping-address="true"
data-billing-address="true"
data-label="Proceed to payment details"
data-image=""
data-description="TrillShirts">
</script>
but if I call it in a .js file I can't get it to post the data taken from the Shipping Details. Here's the code I have:
var handler = StripeCheckout.configure({
key: 'pk_test_JfqHIgPSCG2oWOsJ54PWS0Nl',
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
billingAddress: 'true',
shippingAddress: 'true',
token: function(token) {
console.log(token.id);
console.log(token.email);
// here I try to find the shippingAddress using cosole.log
console.log(token.shippingAddressLine1);
console.log(token.stripeShippingAddressLine1);
// When I eventually have the shipping address, I will insert it in the same way as below
$(".stripeToken").val(token.id);
$(".stripeEmail").val(token.email);
$(".stripe").submit();
}
});
document.getElementById('pay').addEventListener('click', function(e) {
// Open Checkout with further options:
handler.open({
name: 'TrillShirts',
description: 'Childcatcher Tee',
currency: 'gbp',
amount: 2000
});
});
});
Both of the following return undefined in the console, so I can't figure out the format that the Shipping Details come back in.
console.log(token.shippingAddressLine1);
console.log(token.stripeShippingAddressLine1);
Once I know the format and have a successful console log I can use jQuery to insert the data into the form before submit.
Can anyone help?

With Custom Checkout, when shippingAddress is enabled, the shipping details are passed to your token callback function as second argument of the function. This is the args parameter shown in the token callback reference in this doc.
So in your case you would need to modify the signature of your token callback function from function(token) {...} to function(token, args) {...} and then you should be able to get the info from args.
Here is an example: https://jsfiddle.net/rghpes57/3/
in this example the second console.log is the one you want to look at to see how the object looks like.

Related

JHipster - JhiAlertService - How to decide how long alerts are displayed?

I have generated a JHipster project with version 4.9.0.
I am using the JhiAlertService to display various messages to users.
I would like to know how to send in parameters to indicate how long the messages are displayed.
JhiAlertService comes from the ng-jhipster library.
You can view the code of alert.service.ts to see the available parameters.
For customizing the timeout, use the addAlert method and pass it a JhiAlert object containing a timeout parameter:
this.alertService.addAlert({type: 'success', msg: 'A short message', timeout: 1000}, []);
Note that if you are using the i18n option, the msg field is the name of the i18n JSON key, and the params field should contain any information that is interpolated into the message. So for displaying an alert when the "Admin" user is saved successfully, you would use:
this.alertService.addAlert({type: 'success', msg: 'userManagement.updated', params: { param: 'admin' }, timeout: 1000}, []);

displaying custom error messages in stripecheckout.js

I am using stripecheckout.js for handling payments on my site.
I am configuring the object to be send to the stripe pop up as:
stripeHandler = StripeCheckout.configure({
key: $scope.stripeKey,
image: 'img/logo.png',
locale: 'auto',
panelLabel: 'Pay',
color: 'black',
token: handleToken
});
where handleToken is my callback.
Opening the stripe pop up as :
stripeHandler.open({name: //some name,
description: //some description,
amount: //some amount,
currency: //some currency
});
Now I want to display error custom messages related to expiry and cvv fields.
How do I have to pass these messages inside stripe popup.
You can't. Checkout has a number of configuration options, but it is not possible to customize the error messages.
If Checkout supports your language, you can use the data-locale attribute to force a specific language, or set it to auto to use the customer's preferred language automatically.

How to retrieve model data for use inside of another model?

I'm working with an Ember app that ties into a Rails backend through a Sails.js API, and ran into an issue I can't find any similar examples for.
My Messages model has a sender_id column, which corresponds with the id column in my Users model. There is also a Profile model (belongs to User through user_id) that contains the username column, which is what I'd like to be able to access through the Messages model as 'senderName' (i.e., message.senderName). My models and routes are all hooked up, so I have access to all the data I need and everything displays correctly in the browser aside from my senderName function.
The plan was to look up the Profile object through its user_id (using sender_id) inside of Messages, then pull the username field from there. I've been able to receive Promises back from my Profile query, but from there I'm not sure how/if I can access the actual username field. Is there a way to do this, or am I trying to fit a square peg into a round hole?
I also tried accessing username by looking up the User object first (this.store.find('user'), etc.) and using my Rails associations for user.profile.username, but that didn't work either.
Models:
App.Message = DS.Model.extend({
sender_id : DS.attr('number'),
content : DS.attr('string'),
senderName: function() {
var id = this.get('sender_id');
var profile = this.store.find('profile', {user_id: id}).then(function() {
console.log(profile);
// What next? profile.username doesn't work
})
}.property('sender_id')
});
App.Profile = DS.Model.extend({
user: DS.belongsTo('user', { async: true }),
username : DS.attr('string'),
user_id : DS.attr('number')
});
App.User = DS.Model.extend({
profile: DS.belongsTo('profile', { async: true }),
email: DS.attr('string'),
name: DS.attr('string')
});
Template:
<script type="text/x-handlebars" data-template-name="messages/index">
<div class="small-12 column">
{{#each message in model}}
<p>From: {{message.senderName}}</p>
<p>Content: {{message.content}}</p>
{{/each}}
</div>
</script>
Here's an example of the promises I'm receiving back in the browser console:
Promise {_id: 93, _label: undefined, _state: undefined, _result: undefined, _subscribers: Array[0]…}
Thanks for your help!
If I'm getting the question correct, you are having trouble accessing the fields in the model? If so, try:
profile.get('username')
You're really overcomplicating this :-)
Message also belongs to sender, why did you define sender_id as a number?
If you delete senderName and change the sender_id property to:
sender: DS.belongsTo('user', { async: true }),
You can use message.get('sender.profile.username'). I think your main issue here is that you're trying to do an async operation in the computed property, which is a no-no. You can alias the senderName if you like, via senderName: Ember.computed.alias('sender.profile.username') if you end up using it a lot.

LoopBack Remote Methods and Access to Model Data

I've been working on this for hours and I'm completely lost, because the loopback documentation is not helpful.
I'm trying to write application logic into a model. The documentation for that is here. Unfortunately, the example doesn't demonstrate anything useful other than passing an external value into the remote method and returning it again. I'd like to understand how to run a query in this context and access model data, but I have searched for hours and not been able to find documentation on even these simple tasks. Maybe I'm just looking in the wrong places. Can anyone help?
Typically, you can accomplish most things you'd want to do such as querying and accessing model data (CRUD operations) through the built-in methods that all models get; see http://docs.strongloop.com/display/LB/Working+with+data. Defining a remote method (custom REST endpoint) for these would be redundant.
You access the standard model CRUD Node APIs (e.g. myModel.create(), myModel.find(), myModel.updateAll() ) in the remote method code if you want to.
You may also find further related examples in https://github.com/strongloop/loopback-example-app-logic
Here's an example using the Getting Started app https://github.com/strongloop/loopback-getting-started app. It defines a remote method that takes a number arg and prints the name of the coffeeshop with that ID to the console:
This code is in common/models/coffeeshop.js:
module.exports = function(CoffeeShop) {
...
// Return Coffee Shop name given an ID.
CoffeeShop.getName = function(shopId, cb) {
CoffeeShop.findById( shopId, function (err, instance) {
response = "Name of coffee shop is " + instance.name;
cb(null, response);
console.log(response);
});
}
...
CoffeeShop.remoteMethod (
'getName',
{
http: {path: '/getname', verb: 'get'},
accepts: {arg: 'id', type: 'number', http: { source: 'query' } },
returns: {arg: 'name', type: 'string'}
}
);
};
You can use the API Explorer to load http://0.0.0.0:3000/explorer/#!/CoffeeShops/getName then enter a number (there are only three coffee shops in the app initially) as the query param and hit "Try It Out!"
Or just GET a URL like http://0.0.0.0:3000/api/CoffeeShops/getid?id=1
Rand
I finally discovered my problem. Object properties must be loaded in a callback of the function calling the CRUD operation. The following syntax worked for me:
module.exports = function (TestModel) {
TestModel.testRemoteMethod = function (id, name, cb) {
TestModel.findOne({where: {id: id}}, function(err, modelInstance) {
//modelInstance has properties here and can be returned to
//the API call using the callback, for example:
cb(null, {"name": modelInstance.name});
}
}
TestModel.remoteMethod('testRemoteMethod',
//..rest of config

Missing required field: member

{ errors:
[ { domain: 'global',
reason: 'required',
message: 'Missing required field: member' } ],
code: 400,
message: 'Missing required field: member' }
I get this error when I run the following request:
var request = client.admin.members.insert({
groupKey: "some_group#example.com"
, email: "me#example.com"
});
I was authenticated successfully (I received the access token and so on) but when I execute the request above it callbacks that error.
What member field am I supposed to add?
It works fine in API Explorer using groupKey and email fields.
The documentation at https://developers.google.com/admin-sdk/directory/v1/reference/members/insert for admin.members.insert indicates that it requires a groupKey parameter, but that the body (which the node.js library handles as a separate object) should contain a members object containing the role property. See the API Explorer a the bottom of that page as well.
email is part of the form data. The form data must be passed as object in the second argument:
// create the group insert request
var request = client.admin.members.insert({
groupKey: "some_group#example.com"
}, {
email: "me#example.com"
});

Resources