I have tried 2 to 3 possibilities of date formats for the "Start_Date" like
30-05-2018
05-30-2018
30/05/2018
but I am getting the response as
The value "30-05-2018" can't be evaluated into type Date.
The below is my function
public function getPriceList($customer_number){
$url = 'Page/CustomerPrices';
try {
$response = new \stdClass();
$response->status = false;
$options = [
'soap_version' => SOAP_1_1,
'connection_timeout' => 120,
'login' => env('MICROSOFT_DYNAMICS_NAV_USERNAME', ''),
'password' => env('MICROSOFT_DYNAMICS_NAV_PASSWORD', ''),
'exceptions' => true,
];
$soapWsdl = env('MICROSOFT_DYNAMICS_NAV_URI', '').$url;
$client = new SoapClient($soapWsdl, $options);
$response->data = $client->ReadMultiple(['filter'=> [],'Start_Date' => "30-05-2018",'Cust_No'=>$customer_number,'Name'=>'Testing','Price_Comments'=>'','setSize'=>'1']);
$response->status = true;
}catch (Exception $e) {
$response->data = $e->getMessage();
}
return $response;
}
Related
I have migrated my Stripe checkout from legacy version to the new one. The payment does work, but the success redirect URL as well as the DB update does not work.
When I send the request I get redirected to my main page instead of the user subscription page.
Also I do get the error:
Could not determine the URL to request: StripeCustomer instance has invalid ID: (no ID)
I already did some research and also visited the migration documentation from Stripe:
https://stripe.com/docs/payments/checkout/migration
But I do not get the error.
My guess is it is between the lines:
//$payer_id = $customer->id;
$payer_email = $customer->email;
$updateTrx = $trx->update([
'total_price' => $total,
'payment_gateway_id' => $payment_gateway_id,
'payment_id' => $payment_id,
//'payer_id' => $payer_id,
'payer_email' => $payer_email,
'status' => 2,
]);
if ($updateTrx) {
CheckoutController::updateSubscription($trx);
toastr()->success(lang('Payment made successfully', 'checkout'));
return redirect()->route('user.subscription');
}
from:
<?php
namespace App\Http\Controllers\Frontend\Gateways;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Frontend\User\CheckoutController;
use Exception;
use Illuminate\Http\Request;
use Stripe\Checkout\Session;
use Stripe\Customer;
use Stripe\Stripe;
class StripeCheckoutController extends Controller
{
public static function process($trx)
{
if ($trx->status != 0) {
$data['error'] = true;
$data['msg'] = lang('Invalid or expired transaction', 'checkout');
return json_encode($data);
}
if ($trx->plan->interval == 0) {
$planInterval = '(Monthly)';
} elseif ($trx->plan->interval == 1) {
$planInterval = '(Yearly)';
} elseif ($trx->plan->interval == 2) {
$planInterval = '(Lifetime)';
}
$paymentName = "Payment for subscription " . $trx->plan->name . " Plan " . $planInterval;
$gatewayFees = ($trx->total_price * paymentGateway('stripe_checkout')->fees) / 100;
$totalPrice = round(($trx->total_price + $gatewayFees), 2);
$priceIncludeFees = str_replace('.', '', ($totalPrice * 100));
$paymentDeatails = [
'customer_email' => $trx->user->email,
'payment_method_types' => [
'card',
],
'line_items' => [[
'price_data' => [
'currency' => currencyCode(),
'unit_amount' => $priceIncludeFees,
'product_data' => [
'name' => settings('website_name'),
'description' => $paymentName,
],
],
'quantity' => 1,
]],
'mode' => 'payment',
'cancel_url' => route('user.subscription'),
'success_url' => route('ipn.stripe_checkout') . '?session_id={CHECKOUT_SESSION_ID}',
];
try {
Stripe::setApiKey(paymentGateway('stripe_checkout')->credentials->secret_key);
$session = Session::create($paymentDeatails);
if ($session) {
$trx->update(['fees_price' => $gatewayFees, 'payment_id' => $session->id]);
$data['error'] = false;
$data['redirectUrl'] = $session->url;
return json_encode($data);
}
} catch (\Exception $e) {
$data['error'] = true;
$data['msg'] = $e->getMessage();
return json_encode($data);
}
}
public function ipn(Request $request)
{
$session_id = $request->session_id;
try {
Stripe::setApiKey(paymentGateway('stripe_checkout')->credentials->secret_key);
$trx = \App\Models\Transaction::where([['user_id', userAuthInfo()->id], ['payment_id', $session_id], ['status', 1]])->first();
if (is_null($trx)) {
throw new Exception(lang('Invalid or expired transaction', 'checkout'));
}
$session = Session::retrieve($session_id);
//if ($session->payment_status == "paid") {
if ($session->payment_status == "paid") {
$customer = Customer::retrieve($session->customer);
$total = ($trx->total_price + $trx->fees_price);
$payment_gateway_id = paymentGateway('stripe_checkout')->id;
$payment_id = $session->id;
//$payer_id = $customer->id;
$payer_email = $customer->email;
$updateTrx = $trx->update([
'total_price' => $total,
'payment_gateway_id' => $payment_gateway_id,
'payment_id' => $payment_id,
//'payer_id' => $payer_id,
'payer_email' => $payer_email,
'status' => 2,
]);
if ($updateTrx) {
CheckoutController::updateSubscription($trx);
toastr()->success(lang('Payment made successfully', 'checkout'));
return redirect()->route('user.subscription');
}
} else {
throw new Exception(lang('Payment failed', 'checkout'));
}
} catch (\Exception $e) {
toastr()->error($e->getMessage());
return redirect()->route('home');
}
}
}
I am using web3p/ethereum-tx,web3p/web3.php for transfer ERC-1155 token.I attached a image like that image i want transaction method.
My code is below,
$eth->getTransactionCount($from,function($err,$data) use (&$from_addr_nonce){
$from_addr_nonce = gmp_intval($data->value);
});
$from_addr_nonce = Utils::toHex($from_addr_nonce,true);
$web3 = new Web3($binance_url);
$eth = $web3->eth;
$eth->gasPrice(function ($err, $resp) use (&$gasP) {
if ($err !== null) {
throw new \Exception($err->getMessage());
}
$gasP = $resp;
});
$params = [
'nonce' => $from_addr_nonce,
'from' => $from,
'to' => $contractAddress,
'data' => $data
];
// $contract->at($contractAddress)->estimateGas('transfer', $address, $params, function ($err, $gas) use (&$es) {
// if ($err !== null) {
// throw new \Exception($err->getMessage());
// }
// $es = $gas;
// });
$data = "0x".$contract->getData('transfer',$user_wallet->address,1);
//$data = "0x".$contract->mintNFT($from, $nftMint->token_id);
$transaction = new EthTransaction([
'nonce' => $from_addr_nonce,
'from' => $from,
'to' => $contractAddress,
'gas' => $gasP,
'gasPrice' => sprintf('0x%s', $gasP->toHex()),
'gasLimit' => sprintf('0x%s', '895D0'),
'value' => "0x0",
// 'value' =>$amount,
'chainId' => $chain_id,
'data' => $data,
]);
$signedTx = $transaction->sign($privKey);
$txId = '';
// Sending transaction to the blockchain
$contract->eth->sendRawTransaction(sprintf('0x%s', $signedTx), function ($err, $tx) use (&$txId) {
if ($err !== null) {
throw new \Exception($err->getMessage());
}
$txId = $tx;
});
I dont know how to pass tokenid and corresponding quantity.In the getdata function instead of amount i need token id to be pass.
So I am trying to find the best way to get PHP SLIM 3 to log PHP exceptions and errors to a Database table instead of a log. whats the best way to accomplish this? So far in the documentation recommends this.
Dependency:
$app = new \Slim\App();
$c = $app->getContainer();
$c['errorHandler'] = function ($c) {
return function ($request, $response, $exception) use ($c) {
return $response->withStatus(500)
->withHeader('Content-Type', 'text/html')
->write('Something went wrong!');
};
};
What I am having trouble understanding is where do I call this and how could I connect this to log it into a database table that I created. Any Ideas?
Have you tried this for Slim 3?
$config = [
'settings' => [
'displayErrorDetails' => true,
'db' => [
'driver' => 'mysql',
'host' => 'localhost',
'username' => 'root',
'database' => 'test',
'password' => '',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'flags' => [
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
],
]
],
];
$app = new \Slim\App($config);
$container = $app->getContainer();
$container[PDO::class] = function ($container) {
$settings = $container['settings']['db'];
$host = $settings['host'];
$dbname = $settings['database'];
$username = $settings['username'];
$password = $settings['password'];
$charset = $settings['charset'];
$flags = $settings['flags'];
$dsn = "mysql:host=$host;dbname=$dbname;charset=$charset";
return new PDO($dsn, $username, $password, $flags);
}
$container[PDO::class] = function ($container) {
$settings = $container['settings']['db'];
$host = $settings['host'];
$dbname = $settings['database'];
$username = $settings['username'];
$password = $settings['password'];
$charset = $settings['charset'];
$flags = $settings['flags'];
$dsn = "mysql:host=$host;dbname=$dbname;charset=$charset";
return new PDO($dsn, $username, $password, $flags);
};
$container ['errorHandler'] = function ($container ) {
$connection = container[PDO::class];
return function ($request, $response, $exception) use ($connection) {
$row = [
'message' => $exception->getMessage(),
];
$sql = "INSERT INTO error_logs SET message=:message";
$connection->prepare($sql)->execute($row);
return $response->withStatus(500)
->withHeader('Content-Type', 'text/html')
->write('Something went wrong!');
};
};
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setEmailAddress($value);
$newPermission->setExpirationTime('2018-07-13T16:00:00+05:30');
$newPermission->setType($type);
$newPermission->setRole($role);
my drive storage not storing ExpirationTime
There is some minor changes in v3. Check out this links https://developers.google.com/drive/api/v3/reference/permissions/create https://developers.google.com/drive/api/v3/manage-sharing
https://gist.github.com/bshaffer/9bb2cdccd315880ab52f#file-drive-php-L954
insertPermission($service, $fileId, $value, $type, $role) {
$newPermission = new Google_Service_Drive_Permission(array(
'type' => $type,
'role' => $role,
'emailAddress' => $value,
'expirationTime' => '2018-08-18T16:00:00+05:30'
));
try {
$created = $service->permissions->create($fileId, $newPermission);
$permissionsId = $created->id;
$updatedPermission = new Google_Service_Drive_Permission(array(
'role' => $role,
'expirationTime' => '2018-08-18T16:00:00+05:30'
));
$updated = $service->permissions->update($fileId, $permissionsId , $updatedPermission, array(
'fields' => 'id, expirationTime'
));
$expirationTime = $updated->expirationTime;
echo "expirationTime : " . $expirationTime;
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
return NULL;
}
I'm in a situation where I need to call the same method if any exception is thrown to ensure I'm not duplicating any code. However, it's not working as I thought. Here's the relevant code:
public static function getFolderObject($folder_id)
{
$client = new Client('https://api.box.com/{version}/folders', [
'version' => '2.0',
'request.options' => [
'headers' => [
'Authorization' => 'Bearer ' . self::getAccessToken(),
]
]
]);
$request = $client->get($folder_id);
try {
$response = $request->send();
$result = $response->json();
$files = $result['item_collection']['entries'];
} catch (BadResponseException $e) {
$result = $e->getResponse()->getStatusCode();
if ($result === 401) {
self::regenerateAccessToken();
self::getFolderObject();
}
}
return count($files) ? $files : false;
}
As you can see I'm calling the method from the method method under the if condition self::getFolderObject(); to prevent duplicate code again in under the if statement from beginning of the method. However, if I duplicate the code it works as expected. Is there any solution to achieve what I want?
You have missed to return the value and assign the folder_id:
public static function getFolderObject($folder_id)
{
$client = new Client('https://api.box.com/{version}/folders', [
'version' => '2.0',
'request.options' => [
'headers' => [
'Authorization' => 'Bearer ' . self::getAccessToken(),
]
]
]);
$request = $client->get($folder_id);
try {
$response = $request->send();
$result = $response->json();
$files = $result['item_collection']['entries'];
} catch (BadResponseException $e) {
$result = $e->getResponse()->getStatusCode();
if ($result === 401) {
self::regenerateAccessToken();
return self::getFolderObject($folder_id);
}
}
return count($files) ? $files : false;
}