I want to get recipient_signing_uri from the Docusign API response but it returns null - laravel-8

Here is the code
public function send(Request $request): object
{
$apiClient = new ApiClient();
$apiClient->getOAuth()->setOAuthBasePath(env('DS_AUTH_SERVER'));
try {
$accessToken = $this->getToken($apiClient);
} catch (\Throwable $th) {
return back()->withError($th->getMessage())->withInput();
}
$userInfo = $apiClient->getUserInfo($accessToken);
$accountInfo = $userInfo[0]->getAccounts();
$apiClient->getConfig()->setHost($accountInfo[0]->getBaseUri() . env('DS_ESIGN_URI_SUFFIX'));
$envelopeDefenition = $this->buildEnvelope($request);
try {
$envelopeApi = new EnvelopesApi($apiClient);
$result = $envelopeApi->createEnvelope($accountInfo[0]->getAccountId(), $envelopeDefenition);
dd($result);
} catch (\Throwable $th) {
return back()->withError($th->getMessage())->withInput();
}
return view('backend.response')->with('result', $result);
}
When I print $result variable it returns a response like this
container: array:8 [
"bulk_envelope_status" => null
"envelope_id" => "b634f8c5-96c5-4a18-947f-59418d8c4e03"
"error_details" => null
"recipient_signing_uri" => null
"recipient_signing_uri_error" => null
"status" => "sent"
"status_date_time" => "2023-02-16T07:24:39.1570000Z"
"uri" => "/envelopes/b634f8`your text`c5-96c5-4a18-947f-59418d8c4e03"
]
I want to get the value of recipient signing uri in response but in my case it returns null
How I can achieve this? Will anyone suggests?

createEnvelope creates the envelope. It does not give you an URL for an embedded recipient view (signing ceremony). In order to get that URL, you need to make an additional call to
EnvelopeViews:createRecipient/
See this page for more info.
Also
$apiClient->getConfig()->setHost($accountInfo[0]->getBaseUri() . env('DS_ESIGN_URI_SUFFIX'));
You are using the first entry in the UserInfo returned data's accountInfo array. That's not a good idea. Instead, look for the entry that is the user's default account.
Or if your application is designed to work with a specific eSign account, then make sure the user has access to that account.
It is very common for DocuSign customers to have access to more than one account.

Related

Yii2 redirect to previous page after update review

I have a page comp/computer?id=15
it has reviews that can be edited through link
http://comp/computer/update?id=3 = with FORM and submit button
how to go back after sumbit
public function actionUpdate($id)
{
$model = new ReviewForm();
$comment = Review::findOne($id);
if ($model->load($this->request->post())) {
$comment->text = $model->text;
if ($comment->save(false)) {
return $this->redirect(["?id=15"], ); ????????????
}
Yii::$app->session->setFlash(
'success',
'Success'
);
}
$model->setAttributes($comment->getAttributes(['name', 'email', 'text']));
return $this->render('update', compact('model'));
}
simply use referrer.
return $this->redirect(Yii::$app->request->referrer)
If it has no referrer or link open directly then you should either pass computer_id as param or you must have computer_id as foreign key in your review table.
Let say you have relationship with review and computer table. then you can use like this.
$compId = $comment->computer_id; // or 15 or you can paas param here
return $this->redirect(["comp/computer", "id"=> $compId]);
if comp is your hostname then
return $this->redirect(["computer", "id"=> $compId]);
its should be controller/action
return $this->redirect(["controllerId/actionId", "id"=> $compId]);
Send via mobile, sorry for typos.

Get roles by name in a 'guildMemberAdd' handler

Since member.guild.roles.get('roleName') no longer works. I'd like to know if there's an alternative to it.
message.guild.roles.cache.find(role => role.name == 'My Role Name') is not an option, since I don't have access to message object inside the 'guildMemberAdd' handler.
My code works fine using the role id, but I'd like to make it usable for other servers.
** updating my question
This is my code:
const role1 = 'the id number here'; ---> this one I'd like to be by name
const role2 = 'the id number here');
if (collected.first().emoji.name === '😎') {
member.roles.add(role1);
} if (collected.first().emoji.name === '🟩'){
member.roles.add(role2);
} else { return}
You can access the guild from GuildMember
client.on('guildMemberAdd', member => {
// member.guild.roles.cache.find(...) - Callback similar to Array#find()
// member.guild.roles.cache.get(...) - string id parameter only
});

Error Google_Service_BigQueryDataTransfer

I try to work with Google_Service_BigQueryDataTransfer.
I created service account and download json file.
I set GOOGLE_APPLICATION_CREDENTIALS with full path for json file.
I create GoogleClient and Google_Service_BigQueryDataTransfer
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes(array(
Google_Service_Bigquery::BIGQUERY
)
);
$this->service = new Google_Service_BigQueryDataTransfer($client);
I get list of source
$this->service->projects_dataSources->
listProjectsDataSources('projects/' . self::PROJECT_ID);
it works correctly.
I get list of transfers
$this->service->projects_locations_transferConfigs->
listProjectsLocationsTransferConfigs(
'projects/' . self::PROJECT_ID . '/locations/eu'
);
it also works correctly.
I get credentials
$this->service->projects_locations_dataSources->
checkValidCreds(
'projects/'.self::PROJECT_ID.'/locations/europe/dataSources/adwords',
new Google_Service_BigQueryDataTransfer_CheckValidCredsRequest()
);
or
$this->service->projects_dataSources->checkValidCreds(
'projects/'.self::PROJECT_ID.'/dataSources/adwords',
new Google_Service_BigQueryDataTransfer_CheckValidCredsRequest()
);
both requests return null
object(Google_Service_BigQueryDataTransfer_CheckValidCredsResponse)[174]
public 'hasValidCreds' => null
........
and last i try to create transfer
$params = new Google_Service_BigQueryDataTransfer_TransferConfig();
$params->setDestinationDatasetId('stat');
$params->setDisplayName('ID' . $adword_id);
$params->setDataSourceId(self::DATA_SOURCE_ID);
$params->setDataRefreshWindowDays(10);
$params->setDisabled(false);
$params->setParams( ['customer_id'=> (string)$adword_id]);
return $this->service->projects_locations_transferConfigs->create(
$this->getParent(). '/locations/europe',
$params
);
and have error
Google_Service_Exception: {
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
I had this error from page
https://cloud.google.com/bigquery/docs/reference/datatransfer/rest/v1/projects.transferConfigs/create
when hadn't access to bigquery.
Now i use service account and can list dataSource and transfers, but can't create datatransfer.
Can you say, what i do is wrong?
work code
$this->client = new Google_Client();
$this->client->useApplicationDefaultCredentials();
$this->client->setAuthConfig('client_secret.json');
$this->client->setAccessType("offline");
$this->client->setIncludeGrantedScopes(true);
$this->client->setScopes(array(
Google_Service_Bigquery::BIGQUERY,
ADWORDS_SCOPE
)
);
$this->client->setRedirectUri(self::REDIRECT_URI);
$url = $this->getAuthUrl();
header('Location: ' . filter_var($url, FILTER_SANITIZE_URL));
after i authorize in google and give access.
I redirect to code
$this->client = new Google_Client();
$this->client->useApplicationDefaultCredentials();
$this->client->setAuthConfig( MCC_DIR . 'protected/config/client_secret.json');
$this->client->setAccessType("offline");
$this->client->setIncludeGrantedScopes(true);
$this->client->setScopes(array(
Google_Service_Bigquery::BIGQUERY,
ADWORDS_SCOPE
)
);
$this->client->setRedirectUri(self::REDIRECT_URI);
$code = $_GET['code'];
$this->client->authenticate($code);
$tokken = $this->client->getAccessToken();
$this->client->setAccessToken($tokken);
$this->service = new Google_Service_BigQueryDataTransfer($this->client);
$this->service->projects_locations_dataSources->checkValidCreds(
'projects/1069829667403/locations/europe/dataSources/adwords',
new Google_Service_BigQueryDataTransfer_CheckValidCredsRequest()
);
and all works
The default application credentials are insufficient for using BugQuery TransferConfig service (note that unless $response->hasValidCreds is true, the creds are invalid).
Please consider Using OAuth 2.0 for Web Server Applications.
Right code.
You need create OAuth client ID with other type.
Download json credentials.
Get refresh token.
const BQ_API_SCOPE = Google_Service_Bigquery::BIGQUERY.' '.Google_Service_Bigquery::CLOUD_PLATFORM;
const REDIRECT_URI = 'urn:ietf:wg:oauth:2.0:oob';
//....
$scopes = self::BQ_API_SCOPE;
$oauth2 = new OAuth2([
'authorizationUri' => self::AUTHORIZATION_URI,
'redirectUri' => self::REDIRECT_URI,
'tokenCredentialUri' => CredentialsLoader::TOKEN_CREDENTIAL_URI,
'clientId' => $clientId,
'clientSecret' => $clientSecret,
'scope' => $scopes
]);
echo $oauth2->buildFullAuthorizationUri();
$stdin = fopen('php://stdin', 'r');
print'After approving the application, enter the authorization code here: ';
$code = trim(fgets($stdin));
fclose($stdin);
print "\n";
$oauth2->setCode($code);
$authToken = $oauth2->fetchAuthToken();
printf("Your refresh token is: %s\n\n", $authToken['refresh_token']);
Create service with google client use REFRESH_TOKKEN from 3
$client = new Google_Client();
$client->setAuthConfig('client_secret.json');
$client->setAccessType('offline');
$client->setIncludeGrantedScopes(true);
$client->setScopes(array(
Google_Service_Bigquery::BIGQUERY,
Google_Service_Bigquery::CLOUD_PLATFORM,
Google_Service_Bigquery::CLOUD_PLATFORM_READ_ONLY
)
);
if (file_exists(self::ACCESS_TOKKEN_FILE)){
$tokken = file_get_contents(self::ACCESS_TOKKEN_FILE);
$client->setAccessToken($tokken);
if ($client->isAccessTokenExpired()) {
$tokken = $client->fetchAccessTokenWithRefreshToken(REFRESH_TOKKEN);
file_put_contents(self::ACCESS_TOKKEN_FILE, json_encode($tokken));
}
}else{
$tokken = $client->fetchAccessTokenWithRefreshToken(REFRESH_TOKKEN);
file_put_contents(self::ACCESS_TOKKEN_FILE, json_encode($tokken));
}
$this->service = new Google_Service_BigQueryDataTransfer($client);

Can't update product in magento module

have an issue updating magento product from frontend using a module that its function is for customers to create their own products and have the admin approve before enabled(this part is working).
the problem is when a customer tries to updated their admin approved product (as before approval, product states that newly created product is pending, but they can still update the data/attributes created during the product create function, the same attributes that are not updating using the controller)
first of all i have a controller with the action to update the approved/pending customer product
public function editPostAction() {
$id = $this->getRequest()->getParam('productid');
if ( $id !== false ) {
list($data, $errors) = $this->validatePost();
if ( !empty($errors) ) {
foreach ($errors as $message) {
$this->_getSession()->addError($message);
}
$this->_redirect('customer/products/edit/', array(
'id' => $id
));
} else {
$customerId = $this->_getSession()->getCustomer()->getid();
$product = Mage::getResourceModel('customerpartner/customerpartner_product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('customer_id', $customerId)
->addAttributeToFilter('entity_id', $id)
->load()
->getFirstItem();
$product->setName($this->getRequest()->getParam('name'));
$product->setSku($this->getRequest()->getParam('sku'));
$product->setDescription($this->getRequest()->getParam('description'));
$product->setShortDescription($this->getRequest()->getParam('short_description'));
$product->setPrice($this->getRequest()->getParam('price'));
$product->setWeight($this->getRequest()->getParam('weight'));
$product->setStock($this->getRequest()->getParam('stock'));
$product->save();
if ( isset($_FILES) && count($_FILES) > 0 ) {
foreach($_FILES as $image ) {
if ( $image['tmp_name'] != '' ) {
if ( ( $error = $this->uploadImage($image, $id) ) !== true ) {
$errors[] = $error;
}
}
}
}
if ( empty($errors) ) {
$this->_getSession()->addSuccess($this->__('Your product was successfully updated'));
} else {
$this->_getSession()->addError('Product info was saved but was imposible to save the image');
foreach ($errors as $message) {
$this->_getSession()->addError($message);
}
}
$this->_redirect('customer/products/');
}
}
}
as well as a form that on submit is supposed to update the product attributes and images but the page reloads on submit and shows successful saved message but the attributes are not updated and going back to the edit form (for each product created) for that product the values in the update form have the values of the update we just submitted, bet yet the products attributes are not updated in the catalog either (they remain the same values as entered in the create new process)
don't no if to continue to figure out what is going wrong or just move to either use api or direct sql to get the job done.
see this post Magento 1.7: Non-system product attribute not saving in PHP script the problem maybe different but the solution can be found in that post
updated to a new action to call in .phtml see below as it seems to be updating the product data as needed, still wanting to improve..
called in form using /frontendname/editApprovedPost/
public function editApprovedPostAction() {
$id = $this->getRequest()->getParam('productid');
$idproduct = $this->getRequest()->getParam('product_id');
if ( $id !== false ) {
list($data, $errors) = $this->validatePost();
if ( !empty($errors) ) {
foreach ($errors as $message) {
$this->_getSession()->addError($message);
}
$this->_redirect('customer/products/edit/', array(
'id' => $id
));
} else {
- now added more php code to action (in this order) after the } else {...
require_once 'app/Mage.php';
then add admin store for frontend product updates...
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
then get the customer id...
$customerId = Mage::getSingleton('customer/session')->getCustomerId();
then use the forms product Id to get the Product Id to update...
$product = Mage::getModel('catalog/product')->load("".$idproduct."");
then use setName() to update/save the attribute value grabbed from the forms input value...
$product->setName($this->getRequest()->getParam('name'));//use whatever attributes need (only text and text area tested so far)
then save/update product data with...
$product->save();
then add to run through errors...
if ( empty($errors) ) {
$this->_getSession()->addSuccess($this->__('Your product was successfully updated'));
} else {
$this->_getSession()->addError('Product info was saved but was imposible to save the image');
foreach ($errors as $message) {
$this->_getSession()->addError($message);
}
}
$this->_redirect('customer/products/');
}
}
}
then with a form to submit in frontend with customer logged in and customer group config
custom form only visible to Customer Group 2 (default is Wholesale)
form below....
sorry cant paste form to much work to paste the code here, any way using the
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
which i have read in some posts is that to update product in frontend you need to be "admin", which this seems to do just fine. As Noted before, the script was not updating and it was because it is trying to save to a different models data when the data to be updated was an actual product (that has been approved and created using the different models data) and it was updating using
$product = Mage::getResourceModel('customerpartner/customerpartner_product_collection')
would be good to here anyone else's comments
hope this helps someone because was think time to close this build.

Issue with retrieving Magento Frontend Session

I am trying to retrieve the customer's login status from Flex application using AMF call to the Magento Customer API :
Mage::app('default');
$session = Mage::getSingleton('customer/session', array('name'=>'frontend') );
$sessId= $session->getSessionId();
if($session->isLoggedIn()) {
$name = "Hi ". Mage::getModel('customer/session')->getCustomer()->getName();
return 'true' . $name;
}
else{
return 'false ' . $sessId;
}
Only the PHP session ID is returned:
PHPSESSID=i5s1gcemc6r8uquadc4rsk9ou5
But the user is logged into the below ID
frontend=3qdcimcdp7nq4bi8jlovqmnq61
Let me know if I am missing something here.
Use the following code to get the customer ID
Mage::getSingleton('core/session', array('name' => 'frontend'));
$customer = Mage::getSingleton('customer/session',array('name' => 'frontend'));
echo $customerId = $customer->getCustomer()->getId();