Laravel Cashier: Resume a single payment - laravel

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)

Related

How to Users of a specific Room and filter these users with specific spatie tag?

I have a User model that have spatie tags (developer and consultant).
I have a Room model that have many to many relation with User.
I want to return users of a specific room with tag of "consultant".
Can you please help me to do that?
I can find my specific room by id and also I can use relation to get its users but I dont know how to filter them by tag.
I hope you understand my point.
this is what I tried so far but didnt worked!
$room->users->withAnyTags('consultant');
here is my relation:
public function users()
{
return $this->belongsToMany(User::class, 'skyroom_room_user', 'skyroom_room_id', 'user_id')->with('tags');
}
if I run this:
$room->users;
it will return this:
{
"id": "2c8fdf5a-fe94-4216-a3dc-8a49e76c6e34",
"first_name": null,
"last_name": null,
"email": null,
"slug": null,
"username": "+989353785968",
"gender": "male",
"birthday": null,
"national_code": null,
"sheba": null,
"country": null,
"city": null,
"bio": null,
"long_bio": null,
"education": null,
"language": null,
"type": "trainee",
"avatar": null,
"verified_at": null,
"certified_at": null,
"referred_by": null,
"referred_at": null,
"skyroom_user_id": 9379122,
"skyroom_username": "09353785968",
"skyroom_nickname": "مصطفی طاهری",
"skyroom_access": 1,
"created_at": "2021-04-08T13:22:42.000000Z",
"updated_at": "2021-04-08T13:22:42.000000Z",
"deleted_at": null,
"tags": []
},
{
"id": "33b1a31d-1aae-4c38-8c07-0793de5a4216",
"first_name": "حامد",
"last_name": "پوسانه",
"email": "h.pousaneh#gmail.com",
"slug": "hamed",
"username": "+989127426900",
"gender": "male",
"birthday": "1990-05-28 19:37:12",
"national_code": null,
"sheba": null,
"country": "Iran",
"city": "Tehran",
"bio": "مدیریت کسب و کار",
"long_bio": "مدیریت کسب و کار از دانشگاه صنعتی امیرکبیر",
"education": "کارشناسی ارشد",
"language": "فارسی، آذری و انگلیسی",
"type": "trainer",
"avatar": null,
"verified_at": null,
"certified_at": null,
"referred_by": "a9ca25bd-18fb-4271-8155-0a75d9dc31d9",
"referred_at": null,
"skyroom_user_id": 8025480,
"skyroom_username": "09127426900",
"skyroom_nickname": "حامد پوسانه",
"skyroom_access": 3,
"created_at": "2021-04-08T13:06:24.000000Z",
"updated_at": "2021-04-08T15:07:13.000000Z",
"deleted_at": null,
"tags": [
{
"id": "71de78b1-15ad-410d-9778-50cb9b3bd4ca",
"name": {
"en": "consultant"
},
"slug": {
"en": "consultant"
},
"type": "user-system-tag",
"order_column": 3,
"created_at": "2021-04-08T13:06:24.000000Z",
"updated_at": "2021-04-08T13:06:24.000000Z",
"pivot": {
"taggable_id": "33b1a31d-1aae-4c38-8c07-0793de5a4216",
"tag_id": "71de78b1-15ad-410d-9778-50cb9b3bd4ca",
"taggable_type": "App\\Models\\User"
}
},
Assuming you have created your relationships correctly, the syntax for retrieving tagged models would be:
$room->users()->withAnyTags('consultant')->get()
If you wanted to search for multiple tags, you would provide an array to withAnyTags:
$room->users()->withAnyTags(['consultant', 'developer'])->get()

How to change the response in API

I want to change my response in an API. I get the user object in response but i want there the object of join like that here is the code of my Activity Profile Controller in which I get user object.
Currently i get this response.
"user": {
"id": 1,
"facebook_id": null,
"name": "umar",
"surname": "javed",
"email": "uj1#gmail.com",
"username": null,
"date_of_birth": "1993-01-18",
"profile_picture": null,
"occupation": null,
"gender": null,
"city": "lahore",
"country": null,
"course": null,
"university": null,
"discription": null,
"visible_on_feeds": 1,
"visible_on_guestlists": 1,
"created_at": "2018-05-02 10:35:03",
"updated_at": "2019-01-15 14:32:54"
}
public function joinActivity(Activity $activity)
{
$authUser = JWTAuth::parseToken()->toUser();
$userAge = Carbon::parse($authUser->date_of_birth)->age;
if($activity->age_from <= $userAge && $activity->age_to >= $userAge)
{
$authUser->joinActivity($activity, $authUser);
if ($activity->user_id != $authUser->id) {
$user = User::where('id', $activity->user_id)->first();
$user->notify(new JoinedTheActivity($authUser, $activity));
}
$userFriendIds = $authUser->friendslist()->pluck('id')->toArray();
$joinedIds = $activity->joins()->pluck('user_id')->toArray();
$joinedUsers = User::whereIn('id', $joinedIds)->whereIn('id', $userFriendIds)
->where('id', '!=', $authUser->id)->get();
foreach ($joinedUsers as $joinedUser) {
$joinedUser->notify(new FriendJoinedSameActivity($authUser, $activity));
}
return response()->json(['user'=> $authUser], 200);
} else {
return response()->json(['message'=> 'Your are not under the age limit of this Activity']);
}
}
And Here is the code of my ActivityInterest trait:
public function joinActivity(Activity $activity, User $user)
{
if ( $this->isJoiningActivity($activity, $user))
{
$activity->interests()->update(['status'=> Status::JOINED]);
} else {
$joining = $activity->interests()->create([
'user_id' => $user->id,
'activity_id' => $activity->id,
'status' => Status::JOINED,
]);
return $joining->save();
}
}
But I want this response How i can do that Please help Me. Thanks in advance.
"joins": [
{
"id": 71,
"user_id": 1,
"activity_id": 7,
"status": 1,
"created_at": "2018-12-21 07:05:30",
"updated_at": "2018-12-21 07:05:30",
"user": {
"id": 1,
"facebook_id": null,
"name": "umar",
"surname": "javed",
"email": "uj1#gmail.com",
"username": null,
"date_of_birth": "1993-01-18",
"profile_picture": null,
"occupation": null,
"gender": null,
"city": "lahore",
"country": null,
"course": null,
"university": null,
"discription": null,
"visible_on_feeds": 1,
"visible_on_guestlists": 1,
"created_at": "2018-05-02 10:35:03",
"updated_at": "2019-01-15 14:32:54"
},
"activity": {
"id": 7,
"activity_type": "event",
"user_id": 1,
"category_id": 2,
"subcategory_id": 3,
"activity_privacy": "open",
"activity_privacy_visible": 1,
"activity_datetime_from": "2018-07-28 13:35:00",
"activity_datetime_to": "2018-12-12 04:10:12",
"activity_address": "lahore",
"company_id": 3,
"latitude": null,
"longitude": null,
"age_from": 16,
"age_to": 30,
"people_limit": "4",
"activity_picture": null,
"activity_title": "party",
"activity_description": "party bla bla",
"created_at": "2018-05-03 10:49:48",
"updated_at": "2018-09-29 07:57:10",
"user": {
"id": 1,
"facebook_id": null,
"name": "umar",
"surname": "javed",
"email": "uj1#gmail.com",
"username": null,
"date_of_birth": "1993-01-18",
"profile_picture": null,
"occupation": null,
"gender": null,
"city": "lahore",
"country": null,
"course": null,
"university": null,
"discription": null,
"visible_on_feeds": 1,
"visible_on_guestlists": 1,
"created_at": "2018-05-02 10:35:03",
"updated_at": "2019-01-15 14:32:54"
},
"subcategory": {
"id": 3,
"category_id": 2,
"subcategory_name": "party",
"subcategory_picture": "dds",
"created_at": null,
"updated_at": null,
"category": {
"id": 2,
"category_name": "nightlife",
"category_picture": "knk",
"category_color": "#992233",
"created_at": null,
"updated_at": "2018-08-09 11:21:23"
}
}
}
}
]
When you need to change a response in your api, you can create a resource. this is the correct way, and will help you returning the information the way you need it.
In example, php artisan make:resource UserCollection
More info here:
https://laravel.com/docs/5.7/eloquent-resources

How can I get the Bot to list/get the participants or members on a group conversation?

I have created a skypeBot that can be added to a group conversation. Is there a way on how the bot can get the list of participants on from the conversation?
There are at least 2 ways to get the participants of a group conversation with a bot in Skype, but you will get their IDs only:
Case 1: By checking the ConversationUpdate message that is raised when creating the conversation.
Sample (made with one of my bots):
{
"type": "conversationUpdate",
"id": "f:6c9b7aa2",
"timestamp": "2017-06-30T11:40:09.3Z",
"localTimestamp": null,
"serviceUrl": "https://smba.trafficmanager.net/apis/",
"channelId": "skype",
"from": {
"id": "29:1AE5BB....",
"name": null
},
"conversation": {
"isGroup": true,
"id": "19:fd3d....#thread.skype",
"name": null
},
"recipient": {
"id": "28:myBotAppId",
"name": "myBotName"
},
"textFormat": null,
"attachmentLayout": null,
"membersAdded": [{
"id": "29:1AE5BB...",
"name": null
}, {
"id": "29:1DwlGVz...",
"name": null
}, {
"id": "28:myBotAppId",
"name": null
}],
"membersRemoved": [],
"topicName": null,
"historyDisclosed": null,
"locale": null,
"text": null,
"speak": null,
"inputHint": null,
"summary": null,
"suggestedActions": null,
"attachments": [],
"entities": [],
"channelData": null,
"action": null,
"replyToId": null,
"value": null,
"name": null,
"relatesTo": null,
"code": null
}
Here you have 2 users that are in the group conversation in the membersAdded block: 29:1AE5BB.... and 29:1DwlGVz.... The last ID is the bot ID
Case 2: by requesting the API.
You can do a GET request to https://smba.trafficmanager.net/apis/v3/conversations/yourConversationId/members and you will get the same 2 IDs.
See also more details here: https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/core-GetConversationMembers
So from C# code you can do the following:
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
var members = connector.Conversations.GetConversationMembersWithHttpMessagesAsync(activity.Conversation.Id).Result.Body;
For c# you can try this in the messageController
ConnectorClient connector = new ConnectorClient(new System.Uri(activity.ServiceUrl));
var members = connector.Conversations.GetConversationMembersWithHttpMessagesAsync(activity.Conversation.Id).Result.Body;

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

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();

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"]

Resources