Duplicate ID in PUT url when editing Restangular model in ui-router custom path - angular-ui-router

currently I'm setting up restangular to edit my model. Formerly it was ok when I'm not using custom url to show the form, like
http://example.com/admin/clients (I just load the form there).
But, then I use ui-router to setup the URL like this
http://example.com/admin/clients/{clientId}/edit
When I do model.put() or model.save(), the resulting PUT url is wrong. It become like this
PUT http://referral.dev/admin/clients/f2aa1490-5a8f-11e5-b936-b3a54e0c9925/f2aa1490-5a8f-11e5-b936-b3a54e0c9925
It should be like this:
PUT http://referral.dev/admin/clients/f2aa1490-5a8f-11e5-b936-b3a54e0c9925
What I do wrong?
For convenience, here is debug from restangular object:
{
"restangularCollection": false,
"$object": {
"id": "f2aa1490-5a8f-11e5-b936-b3a54e0c9925",
"referrer_id": "f1529d80-5a8f-11e5-8ca1-21124a5fa590",
"email": "Claudia.Kertzmann#hotmail.com",
"first_name": "Isabelle",
"last_name": "Herzog",
"mobile": "450.357.8579x621",
"stage": "member",
"stage_at": "2015-09-09 00:00:00",
"previous_stages": [
{
"stage": "lead",
"stage_at": "2015-08-30 00:00:00"
}
],
"total_investment": 190000,
"email_token": "caf34dddfe00f36b180d459236830934",
"confirmed": false,
"unsubscribed": false,
"transfered_at": null,
"previous_referrers": [],
"created_at": "2015-09-14 03:23:20",
"updated_at": "2015-09-14 03:23:20",
"referrer": {
"id": "f1529d80-5a8f-11e5-8ca1-21124a5fa590",
"email": "Eulalia.Pacocha#Dickens.biz",
"name": "Esperanza Aufderhar Sr.",
"mobile": "658.549.0277",
"role": "referrer",
"organization_id": "f0577b10-5a8f-11e5-984f-f120de15e3c1",
"last_login_at": "0000-00-00 00:00:00",
"suspended": 0
},
"route": "f2aa1490-5a8f-11e5-b936-b3a54e0c9925",
"reqParams": null,
"restangularized": true,
"fromServer": true,
"parentResource": {
"route": "admin/clients",
"parentResource": null
},
"restangularCollection": false
}
}
And, here is the restangular object if don't use custom URL (which working):
{
"id": "f2aa1490-5a8f-11e5-b936-b3a54e0c9925",
"referrer_id": "f1529d80-5a8f-11e5-8ca1-21124a5fa590",
"email": "Claudia.Kertzmann#hotmail.com",
"first_name": "Isabelle",
"last_name": "Herzog",
"mobile": "450.357.8579x621",
"stage": "member",
"stage_at": "2015-09-09 00:00:00",
"previous_stages": [
{
"stage": "lead",
"stage_at": "2015-08-30 00:00:00"
}
],
"total_investment": 190000,
"email_token": "caf34dddfe00f36b180d459236830934",
"confirmed": false,
"unsubscribed": false,
"transfered_at": null,
"previous_referrers": [],
"created_at": "2015-09-14 03:23:20",
"updated_at": "2015-09-14 03:23:20",
"referrer": {
"id": "f1529d80-5a8f-11e5-8ca1-21124a5fa590",
"email": "Eulalia.Pacocha#Dickens.biz",
"name": "Esperanza Aufderhar Sr.",
"mobile": "658.549.0277",
"role": "referrer",
"organization_id": "f0577b10-5a8f-11e5-984f-f120de15e3c1",
"last_login_at": "0000-00-00 00:00:00",
"suspended": 0
},
"route": "admin/clients",
"reqParams": null,
"restangularized": true,
"fromServer": true,
"parentResource": null,
"restangularCollection": false
}
I've tried manually set $object.route to "admin/clients" but the PUT url is still the same.
Thanks.. :)

I've solved it. Formerly I was using:
var models = Restangular.all('admin/clients');
Then use
models.one($stateParams.clientId).get()
to get the model.
The correct way, is use Restangular.one to load model, eg. like this:
vm.model = Restangular.one('admin/clients', $stateParams.clientId).get();

Related

API Platform 3 does not return null data in response body

In API Platform 2.7 the response body contained fields that had a null value, after upgrading to API Platform 3 the response body does not contain fields that have a null value. Is this deliberate or due to a configuration change I need to make.
I executed the same call from the api/docs page for 2.7 and 3.0 I expected the results to be the same.
API Platform 2.7 response for class Patient
{
"#context": "/api/contexts/Patient",
"#id": "/api/patients/8110",
"#type": "Patient",
"account": "/api/accounts/8110",
"accountId": 8110,
"isDependent": false,
"isGuardian": false,
"organization": "/api/organizations/765",
"email": null,
"title": null,
"firstName": "CA",
"middleInitial": "A",
"lastName": "Patient",
"suffix": null,
"photoMedia": null,
"sex": "male",
"birthDate": "2000-01-01T00:00:00+00:00",
"addressLineOne": "5759 Witting Corners",
"addressLineTwo": null,
"city": "Marvintown",
"zipCode": "35507",
"state": {
"#id": "/api/states/681",
"#type": "State",
"abbreviation": "CA"
},
"phoneNumber": "617-491-0000",
"mobileNumber": null,
"workNumber": null
}
API Platform 3.0 response for class Patient
{
"#context": "/api/contexts/Patient",
"#id": "/api/patients/8110",
"#type": "Patient",
"account": "/api/accounts/8110",
"accountId": 8110,
"isDependent": false,
"isGuardian": false,
"organization": "/api/organizations/765",
"firstName": "CA",
"middleInitial": "A",
"lastName": "Patient",
"sex": "male",
"birthDate": "2000-01-01T00:00:00+00:00",
"addressLineOne": "5759 Witting Corners",
"city": "Marvintown",
"zipCode": "35507",
"state": {
"#id": "/api/states/681",
"#type": "State",
"abbreviation": "CA"
},
"phoneNumber": "617-491-0000",
}
Relates to this question
You only need to set skip_null_values to false in your normalization_context, because starting 3.0.0 beta 1 they decided it would become true by default.
If you need it to be false for all resources, you can set the default in your config/packages/api_platform.yaml:
api_platform:
...
defaults:
normalization_context:
skip_null_values: false

'onlineMeetingUrl' is null after call Create Event in Graph api

I use create event api to create an event object with "onlineMeetingUrl: https://meet.lync.com/example/joyce/NLSD7Y62" but the response of "onlineMeetingUrl" is null.
Is it a bug or is there any way to create a new event with 'onlineMeetingUrl'?
Here are my test steps.
Step 1. POST /me/events
{
"#odata.etag": "W/\"BfXylo4WykyAenTZICXL5AAApUQ11g==\"",
"id": "AAMkADVmMzE2MjY0LTZkOGYtNGI4MS1iNWMxLTljYzg3MWY5MWQxMQBGAAAAAABZMfR36TVMQ6yunaqZPvVRBwAF9fKWjhbKTIB6dNkgJcvkAAAAAAENAAAF9fKWjhbKTIB6dNkgJcvkAAClFy2jAAA=",
"createdDateTime": "2018-03-07T02:31:20.6459109Z",
"lastModifiedDateTime": "2018-03-07T02:31:24.2554747Z",
"changeKey": "BfXylo4WykyAenTZICXL5AAApUQ11g==",
"categories": [],
"originalStartTimeZone": "Taipei Standard Time",
"originalEndTimeZone": "Taipei Standard Time",
"iCalUId": "040000008200E00074C5B7101A82E00800000000E5DACD60BCB5D301000000000000000010000000A65419D96CF4C347B8B3B5A340753291",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"subject": "Sky Meeting",
"bodyPreview": "Join online meeting",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": true,
"seriesMasterId": null,
"showAs": "busy",
"type": "singleInstance",
"webLink": "https://outlook.office365.com/owa/?itemid=AAMkADVmMzE2MjY0LTZkOGYtNGI4MS1iNWMxLTljYzg3MWY5MWQxMQBGAAAAAABZMfR36TVMQ6yunaqZPvVRBwAF9fKWjhbKTIB6dNkgJcvkAAAAAAENAAAF9fKWjhbKTIB6dNkgJcvkAAClFy2jAAA%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl": "https://meet.lync.com/example/joyce/NLSD7Y62",
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"body": {
"contentType": "html",
"content": "Join online meeting"
},
"start": {
"dateTime": "2018-03-08T00:00:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2018-03-08T00:30:00.0000000",
"timeZone": "UTC"
},
"location": {
"displayName": "Online meeting"
},
"recurrence": null,
"attendees": [],
"organizer": {
"emailAddress": {
"name": "Joyce",
"address": "joyce#example.com"
}
}
}
Step 2. The onlineMeetingUrl in the response event object is null.
{
...
"onlineMeetingUrl": null,
...
}
The onlineMeetingUrl property is not writable. We will update the documentation to reflect this.
Add these params in the request body
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness"
onlineMeetingUrl is null in response even while passing "isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness"

Laravel Cashier: Resume a single payment

after a successful payment I store the stripe id on a mysql table. With that id I would like to retrieve all the details stored in the stripe database.
So is it possible to resume a single payment by the stripe id?
Thanks
Here is the documentation you need to use: https://stripe.com/docs/api/php#retrieve_customer
Use the "customer retrieve" Stripe API call to retrieve details about the customer's purchase:
Stripe::setApiKey(Config::get('your_stripe_secret_key_here'));
$customer_object = Customer::retrieve(customers_stripe_id);
This will return the following JSON:
Stripe\Customer JSON: {
"id": "cus_7KJZQ8Z6jfSSMl",
"object": "customer",
"account_balance": 0,
"created": 1447172728,
"currency": "usd",
"default_source": "card_175evz2eZvKYlo2CKoS2WEDk",
"delinquent": false,
"description": "Bingo|www|0c1234567890",
"discount": null,
"email": null,
"livemode": false,
"metadata": {
},
"shipping": null,
"sources": {
"object": "list",
"data": [
{
"id": "card_175evz2eZvKYlo2CKoS2WEDk",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"customer": "cus_7KJZQ8Z6jfSSMl",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 5,
"exp_year": 2016,
"funding": "credit",
"last4": "4242",
"metadata": {
},
"name": null,
"tokenization_method": null
}
],
"has_more": false,
"total_count": 1,
"url": "/v1/customers/cus_7KJZQ8Z6jfSSMl/sources"
},
"subscriptions": {
"object": "list",
"data": [
],
"has_more": false,
"total_count": 0,
"url": "/v1/customers/cus_7KJZQ8Z6jfSSMl/subscriptions"
}
}
Here is Stripe's version of the API call:
\Stripe\Stripe::setApiKey("your_secret_key");
\Stripe\Customer::retrieve("the_customers_id");
Make sure to import the \Stripe classes by adding this at the top of your Model or Controller:
use Stripe\Customer;
use Stripe\Stripe;
if you want to use "Stripe" instead of \Stripe\Stripe and \Stripe\Customer prefixes)

How can I access elements of a JSON return from a Stripe api call?

I am using ruby and sinatra. After a Stripe API call, I want to access an element, from a JSON return, and put it into my database.
The ruby code is:
require 'sinatra'
require 'stripe'
require 'pg'
require 'sequel'
get '/save_customer' do
customer = Stripe::Customer.retrieve("cus_6EfJSbJ8gCTxxx")
puts customer
last4 = customer["sources"]["data"]["last4"]
DB[:stripe_customers].insert(:user_id=>user_id, :email=>email, :stripe_customer_id=>customer_id, :stripe_customer_card=> last4)
end
The JSON (taken from the API docs, not my return) is as follows:
{
"object": "customer",
"created": 1431570089,
"id": "cus_6EfJSbJ8gCTxxx",
"livemode": false,
"description": "Example customer",
"email": null,
"delinquent": false,
"metadata": {
},
"subscriptions": {
"object": "list",
"total_count": 0,
"has_more": false,
"url": "/v1/customers/cus_6EfJSbJ8gCTMrd/subscriptions",
"data": [
]
},
"discount": null,
"account_balance": 0,
"currency": "usd",
"sources": {
"object": "list",
"total_count": 1,
"has_more": false,
"url": "/v1/customers/cus_6EfJSbJ8gCTMrd/sources",
"data": [
{
"id": "card_162ByRBVd5ndD62KfaONcG4G",
"object": "card",
"last4": "4242",
"brand": "Visa",
"funding": "credit",
"exp_month": 12,
"exp_year": 2018,
"country": "US",
"name": null,
"address_line1": null,
"address_line2": null,
"address_city": null,
"address_state": null,
"address_zip": "123456",
"address_country": null,
"cvc_check": "pass",
"address_line1_check": null,
"address_zip_check": "pass",
"dynamic_last4": null,
"metadata": {
},
"customer": "cus_6EfJSbJ8gCTxxx"
}
I have tried:
last4 = customer[:data][:sources][:last4]
and with "" as above.
The error message has varied, currently TypeError - no implicit conversion of String into Integer. I assume this is because I have not extracted the element I need correctly, or it could mean that the api call did not work but I assume that it did.
Try this:
last4 = customer["sources"]["data"][0]["last4"]

How to get filtered activity stream using Yammer API?

Yammer Activity Stream is available at:
https://www.yammer.com/api/v1/streams/activities.json?access_token=
This successfully results in all the recent activities like:
{
"items": [
{
"id": "/users/www.yammer.com-341514-1508953644/rollups/45191477209921-45191477209921",
"unseen": true,
"icon": "/images/notifications/page_add.png",
"icon_name": null,
"category": "file-create",
"message": "[[user:1508783078]] uploaded [[uploaded_file:24511980]].",
"heading": "",
"created_at": "2014/10/02 07:07:42 +0000",
"objects": [],
"actions": [],
"subject": {
"type": "uploaded_file",
"id": 24511980
},
"meta": null,
"client_type": "unknown",
"client_url": "https://www.yammer.com",
"client_icon": "https://mug0.assets-yammer.com/mugshot/images/16x16/3rd_party.png",
"client_large_icon": "https://mug0.assets-yammer.com/mugshot/images/75x75/3rd_party.png",
"image": "https://mug0.assets-yammer.com/mugshot/images/48x48/no_photo.png",
"third_party": false
},
{
"id": "/users/www.yammer.com-341514-1508953644/rollups/45191475863746-45191475863746",
"unseen": true,
"icon": "/images/notifications/page_add.png",
"icon_name": "page",
"category": "file-download",
"message": "[[user:1508783078]] downloaded [[uploaded_file:24373320]] from the [[group:3455089]] group.",
"heading": "",
"created_at": "2014/10/02 07:07:00 +0000",
"objects": [
{
"id": 24373320,
"type": "uploaded_file"
}
],
"actions": [],
"subject": {
"type": "uploaded_file",
"id": 24373320
},
"meta": null,
"client_type": "unknown",
"client_url": "https://www.yammer.com",
"client_icon": "https://mug0.assets-yammer.com/mugshot/images/16x16/3rd_party.png",
"client_large_icon": "https://mug0.assets-yammer.com/mugshot/images/75x75/3rd_party.png",
"image": "https://mug0.assets-yammer.com/mugshot/images/48x48/no_photo.png",
"third_party": false
},
]}
QUESTION:
I am trying to get all the recent activities after a certain time-stamp or after a certain offset. Is there any query parameter for that?
this is
older_than="/users/www.yammer.com-341514-1508953644/rollups/45191475863746-45191475863746"
that would return all the activities older than the last activities you shew in your sample return value

Resources