I am trying to integrate paypal payment module with one of my application. For that I used ci-merchant. I did the following code:
Controller:
$this->load->helper('language');
$this->load->library('merchant');
$this->merchant->load('merchant_paypal_express');
$settings = array(
'username' => 'amas***-facilitator_api1.opl****.com',
'password' => '1383***828',
'signature' => 'AQU0e5vuZCvSg*****oSa.sGUDlpAdkd1coWah3Y.Bvq-lz3WLKI-t-q',
'test_mode' => true);
$this->merchant->initialize($settings);
$params = array(
'amount' => 100.00,
'currency' => 'USD',
'return_url' => base_url().'payment',
'cancel_url' => base_url().'payment'
);
$response = $this->merchant->purchase_return($params);
var_dump($response);
It gives me the following result:
object(Merchant_response)[23]
protected '_status' => string 'failed' (length=6)
protected '_message' => string 'Invalid token.' (length=14)
protected '_reference' => null
protected '_data' => null
protected '_redirect_url' => null
protected '_redirect_method' => string 'GET' (length=3)
protected '_redirect_message' => null
protected '_redirect_data' => null
Some one please tell me about Invalid token error and about what is the best way to use ci-merchat.
Please add
$settings = $this->merchant->default_settings();
and After that
$settings = array('username' => 'amas*-facilitator_api1.opl**.com',
'password' => '1383***828',
'signature' => 'AQU0e5vuZCvSg*****oSa.sGUDlpAdkd1coWah3Y.Bvq-lz3WLKI-t-q',
'test_mode' => true)
;
Related
When I try to config mail from livewire controller and send mail with foreach loop then show the error "Illuminate\Mail\MailManager::getConfig(): Argument #1 ($name) must be of type string, null given, called in /Users/msurubel/Web_Application_Projects/Lourent/Email_Marketing_App/main_app/vendor/laravel/framework/src/Illuminate/Mail/MailManager.php on line 107"
Controller Code
$getAllSubscribers = subscribers::wheregroup_id($this->SelectingGroupInput)->get();
//Config SMTP
$getSMTPConfig = smtp_configs::whereref_id($this->SelectingSMTPConfigInput)->first();
$mailConfig = array(
'mailer' => $getSMTPConfig->mailler,
'host' => $getSMTPConfig->host,
'port' => $getSMTPConfig->port,
'from' => array('address' => $this->SendingFromEmail, 'name' => $this->SendingFromName),
'encryption' => $getSMTPConfig->encryption,
'username' => $getSMTPConfig->username,
'password' => $getSMTPConfig->password,
);
Config::set('mail', $mailConfig);
foreach ($getAllSubscribers as $lists){
$getSubscriberData = subscribers::whereid($lists->id)->first();
$details = [
'CompanyName' => $this->SendingFromName,
'subject' => $this->SendingSubjectline,
'MailBody' => "Hi, How are you.",
'name' => "App",
];
Mail::to("$getSubscriberData->email")->send(new BulkMail($details));
}
This my error view - https://flareapp.io/share/x7Xp90w7#F60
I deployed a Laravel-Livewire on Digital Ocean and now I'm having a Mixed content problem when I try to upload a file.
Here is the error:
UploadManager.js:131 Mixed Content: The page at 'https://intake.freejiji.ca/clients/3/extensions' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://intake.freejiji.ca/livewire/upload-file?expires=1625251608&signature=9d98c598db4f6fccc01c009bcfc3051c6a97b56f4058f4d9489a8d30d6d497c2'. This request has been blocked; the content must be served over HTTPS.
The error happens when after I click "Select File" and chose the .csv file I want. Since I'mdoing this on a livewire component I'm not sure how to fix this so that the request goes over HTTPS instead of HTTP.
I was able to fix similar problems on the app by changing "asset()" with "secure_asset()"
and "route()" with "secure_url()" but in this case I'm not sure what to do.
Here is the whole "Import" component:
<?php
namespace App\Http\Livewire\Modals;
use Validator;
use Livewire\Component;
use App\Http\Traits\Csv;
use App\Models\AccountUser;
use Livewire\WithFileUploads;
use Illuminate\Validation\Rule;
use Illuminate\Support\Facades\Auth;
class ImportExtensions extends Component
{
use WithFileUploads;
public $clientID;
public $showModal = false;
public $upload;
public $columns;
public $fieldColumnMap = [
'first_name' => '',
'last_name' => '',
'email' => '',
'password' => '',
'extension' => '',
'user_type' => '',
];
protected $rules = [
'fieldColumnMap.first_name' => 'required|max:255',
'fieldColumnMap.last_name' => 'required|max:255',
'fieldColumnMap.email' => 'required|max:255',
'fieldColumnMap.password' => 'required|max:255',
'fieldColumnMap.extension' => 'required|max:255',
'fieldColumnMap.user_type' => 'required|max:255',
];
protected $validationAttributes = [
'fieldColumnMap.first_name' => 'First Name',
'fieldColumnMap.last_name' => 'Last Name',
'fieldColumnMap.email' => 'Email',
'fieldColumnMap.password' => 'Password',
'fieldColumnMap.extension' => 'Extension',
'fieldColumnMap.user_type' => 'User Type',
];
public function updatingUpload($value)
{
Validator::make(
['upload' => $value],
['upload' => 'required|mimes:csv'],
)->validate();
}
public function updatedUpload()
{
$this->columns = Csv::from($this->upload)->columns();
$this->guessWhichColumnsMapToWhichFields();
}
public function import()
{
// Validate that you are importing any data
$this->validate();
$importCount = 0;
Csv::from($this->upload)
->eachRow( function ($row) use (&$importCount){
$eachRow = $this->extractFieldsFromRow($row);
// Validate each Row of the csv file
$validatedData = Validator::make([
'first_name' => $eachRow['first_name'],
'last_name' => $eachRow['last_name'],
'email' => $eachRow['email'],
'password' => $eachRow['password'],
'extension' => $eachRow['extension'],
'user_type' => $eachRow['user_type'],
],[
'first_name' => 'required',
'last_name' => 'required',
'password' => 'required|max:255',
'user_type' => 'required|in:user,admin',
'email' => 'required|email|unique:account_users',
'extension' => ['required', 'numeric', Rule::unique('account_users', 'extension')
->where(function($query)
{return $query->where("account_id", $this->clientID);
})],
],);
if($validatedData->fails()){
$this->notify(['error','Oops something went wrong!']);
}else{
AccountUser::create([
'user_id' => Auth::user()->id,
'account_id' => $this->clientID,
'first_name' => $eachRow['first_name'],
'last_name' => $eachRow['last_name'],
'email' => $eachRow['email'],
'password' => $eachRow['password'],
'extension' => $eachRow['extension'],
'user_type' => $eachRow['user_type'],
]);
$importCount++;
}
});
$this->reset();
$this->emit('refreshExtensions');
if($importCount!=0) $this->notify(['success','Successfully Imported '.$importCount.' Extensions']);
}
public function guessWhichColumnsMapToWhichFields()
{
$guesses = [
'first_name' => ['first_name', 'name'],
'last_name' => ['last_name'],
'email' => ['email'],
'password' => ['password', 'pass'],
'extension' => ['extension', 'ext'],
'user_type' => ['user_type', 'user', 'type'],
];
foreach ($this->columns as $column) {
$match = collect($guesses)->search(fn($options) => in_array(strtolower($column), $options));
if ($match) $this->fieldColumnMap[$match] = $column;
}
}
public function extractFieldsFromRow($row)
{
$attributes = collect($this->fieldColumnMap)
->filter()
->mapWithKeys(function($heading, $field) use ($row) {
return [$field => $row[$heading]];
})
->toArray();
return $attributes;
}
public function downloadTemplate()
{
$filename = 'extensions_template.xls';
$path = public_path('files/' . $filename);
return response()->download($path, $filename, [
'Content-Type' => 'application/vnd.ms-excel',
'Content-Disposition' => 'inline; filename="' . $filename . '"'
]);
}
}
If you get mixed content problem it is mostly about you fetching the assets or resources from different http scheme. Here you are using HTTP to fetch data in HTTPS site. Change all the links to have HTTPS link.
If you want to force all the routes to use https you can achieve this by using following code.
if(env('APP_ENV', 'production') == 'production') { // use https only if env is production
\URL::forceScheme('https')
}
The above should solve your problem as all contents now will load from https.
I am trying to add drop down box information:
USERNAME EMAIL ROLE
3 user user#mail.com 12345
How to add role so that it shows administrator or Manager? instead of the codes?
models/Mpages.php
public function add_user()
{
$options = [
'roles' => 'administrator',
];
$hash = password_hash($this->input->post('password'), PASSWORD_BCRYPT, $options);
$data = array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $hash,
'role' => form_dropdown('roles', $options, 'administrator')
);
return $this->db->insert('login', $data);
}
controllers/Cpages.php
public function addusers() {
$data['successmessage'] = "";
$data['options'] = array(
'administrator' => 'Administrator',
'manager' => 'Manager',
);
$this->Mpages->add_user();
$this->load->view('addusers', $data);
}
Here is the answer key:
controllers/Cpages.php
public function addusers() {
$data['successmessage'] = "";
$data['options'] = array(
'administrator' => 'Administrator',
'manager' => 'Manager',
);
$this->Mpages->add_user();
$this->load->view('addusers', $data);
}
models/Mpages.php
public function add_user()
{
$options = [
'roles' => 'administrator',
];
$hash = password_hash($this->input->post('password'), PASSWORD_BCRYPT, $options);
$data = array(
'username' => $this->input->post('username'),
'email' => $this->input->post('email'),
'password' => $hash,
'role' => $this->input->post('roles')
);
return $this->db->insert('login', $data);
}
so i am using laravel 4.2. my problem is I cannot echo the data from my redirect route. how can i access it the right way? I tried searching to get the right answer but it didn't help me.
public function postLogin()
{
$timeIn = date('Y-m-d G:i:s');
$userLog = New UserLog;
$userLog->username = Input::get('username');
$userLog->time_in = $timeIn;
$userLog->save();
$users = $userLog;
return Redirect::route( 'account' )
->with( 'users', $users );
}
public function account(){
$data = Session::get('users');
var_dump($data );
echo $data->username;// this one throws an error
}
I can see that it has values in var_dump($data).
object(__PHP_Incomplete_Class)[92]
public '__PHP_Incomplete_Class_Name' => string 'UserLog' (length=7)
public 'timestamps' => boolean false
public 'table' => string 'userlogs' (length=8)
protected 'connection' => null
protected 'primaryKey' => string 'id' (length=2)
protected 'perPage' => int 15
public 'incrementing' => boolean true
protected 'attributes' =>
array (size=3)
'username' => string 'user' (length=4)
'time_in' => string '2015-07-28 15:11:43' (length=19)
'id' => int 240
protected 'original' =>
array (size=3)
'username' => string 'user' (length=4)
'time_in' => string '2015-07-28 15:11:43' (length=19)
'id' => int 240
these are my routes file
Route::get('/login', array(
'uses' => 'TimeController#login',
'as' => 'login')
);
Route::post('/postLogin', array(
'uses' => 'SessionsController#postLogin',
'as' => 'postLogin')
);
Route::get('/account', array(
'uses' => 'SessionsController#account',
'as' => 'account')
);
I felt like i made a huge success just by displaying the data, and the problem causing me to get errors is the __PHP_Incomplete_Class as you can see on my var_dump($data) above. To access the $data correctly, i need to unserialize it first before accessing the regular way. here i just added one line of code and everything works very well. thanks to this post unserializing.
public function account(){
$data = Session::get('users');
$data = unserialize(serialize($data)); //added code to unserialize the __PHP_Incomplete_Class
var_dump($data);
echo $data->username;
}
in my var_dump($data) the __PHP_Incomplete_Class is now gone
object(UserLog)[143]
public 'timestamps' => boolean false
protected 'table' => string 'userlogs' (length=8)
protected 'connection' => null
protected 'primaryKey' => string 'id' (length=2)
protected 'perPage' => int 15
public 'incrementing' => boolean true
protected 'attributes' =>
array (size=3)
'username' => string 'user' (length=4)
'time_in' => string '2015-07-28 19:57:08' (length=19)
'id' => int 276
protected 'original' =>
array (size=3)
'username' => string 'user' (length=4)
'time_in' => string '2015-07-28 19:57:08' (length=19)
'id' => int 276
My validation fails, so my test for this message throws an ValidationException every time.
"Not all fields are filled out correct". Why? Analoguosly, it works for users (another method).
MODEL:
public $validate = array(
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Name can not be empty',
),
'unique' => array(
'rule' => 'isUnique',
'message' => 'This name is already used.',
),
),
'address' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'Address can not be empty',
),
...
public function saveNewInstitution($institutionData, $userId) {
$institutionData[$this->alias]['is_active'] = 1;
$institutionData[$this->alias]['user_id'] = $userId;
$this->create();
$this->set($institutionData);
if ($this->validates()) {
return $this->save();
} else {
throw new ValidationException('Not all fields are filled out correct');
}
}
TESTclass:
public function testSaveNewInstitution() {
$data = array(
'Institution' => array(
'name' => 'Spitex Staufen',
'address' => 'Hauptweg 4',
'postcode' => '1234',
'city' => 'huuh',
'phone_number' => '123 456 78 90',
'email' => 'staufen#spitex.huuh',
'comment' => '',
'institution_type_id' => 5
));
$expected = array(
'Institution' => array(
'id' => 2,
'name' => 'Spitex Staufen',
'address' => 'Hauptweg 4',
'postcode' => '1234',
'city' => 'huuh',
'phone_number' => '123 456 78 90',
'email' => 'staufen#spitex.huuh',
'comment' => '',
'is_active' => TRUE,
'user_id' => 2,
'institution_type_id' => 5
));
$result = $this->Institution->saveNewInstitution($data, 2);
$this->assertEqual($result, $expected);
}
and all the Exceptionhandling methods like this:
public function testSaveNewInstitutionExceptionName() {
$this->setExpectedException('ValidationException');
$this->Institution->saveNewInstitution($this->__nameEmpty, 2);
}
I don't know if i got it really - is your Testclass failing or is the saveNewInstitution() function making you troubles? Did you try to check if the saveNewInstitution() is working correct by hand - put some data in a form an pass it to your function?
Maybe it's just a small thing and you have an entry with id=2 in your database an you got a duplicate key exception overwritten by your own exception method testSaveNewInstitutionExceptionName().