I am trying to load previously used cards using the Stripe API using Laravel using this link from Stripe https://stripe.com/docs/api/payment_methods/list?lang=php
Here is the snippet of code from my controller:
$stripe = new \Stripe\StripeClient(
'sk_test_51GueZuLq4MEy
);
$customer_id = "cus_HhnBT9fpjxW3hn";
$paymentMethods = $stripe->paymentMethods->all([
'customer' => $customer_id,
'type' => 'card',
]);
$pm = ($paymentMethods->data);
return view('payment.details', $pm);
However when I am trying to pass the card data into my view I am unable to do so. The variable I am passing in views is:
{{ $pm }}
The error message I get is that my variable is not recognised. The data I am trying to access is $paymentmethods->-data->card->last4
Any help is always appreciated
$stripe->paymentMethods->all returns an object with a data attribute, where the data is an array of PaymentMethods, in this case, you'll likely want to access the first element of data.
Try updating to:
$pm = $paymentMethods->data[0];
Related
My api receives an json object posted from my React app. The object has two properties, one holding an array of objects and the other holds an id number. Because the first array cannot be validated by Symfony's form validation, I have created an custom restraint for it.
$data = json_decode($request->getContent(), true);
$custom_constraint = new Assert\blah blah;
$errors = $validator->validate($data['datas'], $custom_constraint );
if (count($errors) > 0 ) {
$errorsString = (string) $errors;
return new JsonResponse(
[
'validation failed' => $errorsString
]);
}
This validation works by itself, but I also want to add the validation for the id number
$errors = $validator->validate($data['id'], new Assert\Type('integer'));
Now I have two results in the $errors object, how do I combine them into one error object that output errors for any one of them?
You should use AssertCollection. It's demonstrate here: How to Validate Raw Values
I have a single form which I am using to create and edit information.
I am using Form::model to show all the data in the edit form which are queried from the database. Now I had to add another form part whose data is being stored in a different table. But I need to show those data during edit in the same form. I have tried to put two parameter in the form:model which did not work or I am doing it wrong.
{!! Form::model([$employee_data,$edu_info],['route'=>['employee.update',$employee_data->id],'method'=>'put','files'=> true]) !!}
Then I tried to merge the queried data in my controller like this:
public function edit($id)
{
$edit_info['title'] = 'Edit User';
$edit_info['country'] = Country::all();
$employee_basic = Employee::withTrashed()->where('id',$id)->first();
$employee_edu = EmployeeEdu::withTrashed()->where('employee_id',$id)->first();
$employee_all_data = $employee_basic->merge($employee_edu);
$employee_all_data->all();
$edit_info['employee_data'] = $employee_all_data;
return view('admin.employee.edit',$edit_info);
}
This did not work either. I get the following error:
Call to undefined method Illuminate\Database\Query\Builder::merge()
How can I achieve my intended result?
EDIT: I tried to use ->get() instead of ->first(), In this case I do not get the error but my merge does not work as when I dd($employee_all_data) it gives me only the value of $employee_edu.
Try this:
$employee_all_data = $employee_basic->toArray() + $employee_edu->toArray();
I am currently working in codeigniter and I am new to this.
I was wondering how to retrieve the JSON values using API call .
Can anyone suggest me where should I start.
Many Thanks in advance
Pass your array of row to json_encode();example for method of controller is below
public function getUserList() {
header('Content-Type: application/json');
$query = $this->db->get('mytable');
if(count($query) > 0) {
$message = array('status' => 'true' , 'message' => 'Record get successfully' , 'data' => $return );
}else{
$message = array('status' => 'false' , 'message' => 'Record not found.' );
}
echo json_encode($message);
}
Codeigniter does not have an inbuilt HTTP method so you need to use other things in php to achieve this.
There are 2 ways, you can use cURL, but honestly... it's convoluted... but read this: http://php.net/manual/en/book.curl.php
Another method is using stream_context_create() http://php.net/manual/en/function.stream-context-create.php
I strongly suggest using this 2nd one as its much easier to work with (in context with curl..
Much of how you setup your request depends on the API you are referencing with and the kind of requests it allows: GET, POST ... and what kind of header information it requires you to send over as well do they require oAuth header?
There is no 1 bunch of code fits all, I had to create a full custom library to integrate codeigniter into Magento, it took many hours.
I'm working with Stripe's API and am trying to retrieve data. I have the code below:
$data = \Stripe_Invoice::all(array(
"customer" => $user->customer_id
));
If I set the AJAX response equal to $data, the response is shown as empty ( {} ). If I debug it in the backend, I get a huge list of all kinds of awesome properties to use. All I do is this:
debug($data); // returns huge data set
The trouble is that I can't access the variable in the frontend. I want to use:
console.log(response);
html += response.url;
And things to that effect, but the data is completely empty when the front end interprets it, for some reason.
In the same effect, I can't set it as a session either (I used to set session logs to debug instead of using the debug feature).
$data // can be accessed on the frontend if we use just php to set a variable
$_SESSION['log'] = $data; // empty
What's going on? I'm using the PHP framework CakePHP 3 (latest version of Beta). I think it has something to do with returning the data as serialized (maybe?) but that wouldn't explain the session logging. This happens right before we send the data back:
$this->set(compact('data', $data));
$this->set('_serialize', 'data');
If $data is not empty than you should just use the set method in the controller
$this->set(compact('data', $data));
Than you should have the corresponding view at /src/Template/ControllerName/json/methodName.ctp (Change ControllerName and methodName to what you have)
This file should be this.
<?php
print json_encode($data);
?>
That is all. You should have your data on your client side as a json object.
Turns out the answer was that the values could not be displayed while the array was protected. Calling Stripe's method __toArray() on the Stripe object made the data accessible, and setting worked past this point.
$data = \Stripe_Invoice::all(array(
"customer" => $user->customer_id
));
$data = $data->__toArray();
$this->set(compact('data', $data));
$this->set('_serialize', 'data');
We are developing a website using ZF2. We alreday started the project. We installed ZF2 skelton application and integrated the album module. Everything seems working. Now we are trying to integrate multiple zend forms in a module. Forms eveyrything we made [ by modifying the albulm module elements) I am able to insert/update/delete etc data in to the default table that set on the module.php file [this is for form 1].
I have another form which requires to insert/delete/update to another table, I created new form class, Table class (on model) etc. When I tried to insert the data in to Db using custom query format, it throws error:
File:
/home/catholic/public_html/propertydosth/vendor/zendframework/zendframework/library/Zend/Db/Sql/Insert.php:298
Message:
The key adapter was not found in this objects column list.
It seems adaptor value is not getting something..
My Code for insert query:
$adapter = $this->tableGateway->getAdapter();
$sql = new Sql($adapter);
$insert = $sql->insert('dad_cms');
$newData = array(
'category_id' => $admin->category_id,
'cms_title' => $admin->cms_title,
'cmd_desc' => $admin->cmd_desc,
'seo_keywords' => $admin->seo_keywords,
'seo_titles' => $admin->seo_titles
);
$insert->values($newData);
$selectString = $sql->getSqlStringForSqlObject($insert);
$results = $insert->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
I am getting correct query value when I echoed $selectString .
Any one please suggest what is wrong in my code to get it done.
Finally Sam helped me on this issue:
So correct Answer become [this will be helpful somebody having similar issue. Even I spent lot of time to debug the same]:
$adapter = $this->tableGateway->getAdapter();
$sql = new Sql($adapter);
$insert = $sql->insert('dad_cms');
$newData = array(
'category_id' => $admin->category_id,
'cms_title' => $admin->cms_title,
'cmd_desc' => $admin->cmd_desc,
'seo_keywords' => $admin->seo_keywords,
'seo_titles' => $admin->seo_titles
);
$insert->values($newData);
$selectString = $sql->getSqlStringForSqlObject($insert);
$results = $adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);