PayPal Payout API REQUIRED_SCOPE_MISSING - php

I am trying to implement payout request using CURL. But I am getting this error: "name":"REQUIRED_SCOPE_MISSING","message":"Access token does not have required scope.","information_link":"https://developer.paypal.com/docs/api/payments.payouts-batch/#errors"
I have already checked on payouts scope in-app settings on developer dashboard.
Here is code:
$host = 'https://api.sandbox.paypal.com';
$clientId = 'id';
$secret = "secret";
$token = '';
function get_access_token($url, $postdata) {
global $clientId, $clientSecret;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERPWD, $clientId . ":" . $clientSecret);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$response = curl_exec( $curl );
if (empty($response)) {
die(curl_error($curl));
curl_close($curl);
} else {
$info = curl_getinfo($curl);
echo "Time took: " . $info['total_time']*1000 . "ms\n";
curl_close($curl);
if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
echo "Received error: " . $info['http_code']. "\n";
echo "Raw response:".$response."\n";
die();
}
}
$jsonResponse = json_decode( $response );
return $jsonResponse->access_token;
}
function make_post_call($url, $postdata) {
global $token;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$token,
'Accept: application/json',
'Content-Type: application/json'
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$response = curl_exec( $curl );
if (empty($response)) {
die(curl_error($curl));
curl_close($curl);
} else {
$info = curl_getinfo($curl);
echo "Time took: " . $info['total_time']*1000 . "ms\n";
curl_close($curl); // close cURL handler
if($info['http_code'] != 200 && $info['http_code'] != 201 ) {
echo "Received error: " . $info['http_code']. "\n";
echo "Raw response:".$response."\n";
die();
}
}
$jsonResponse = json_decode($response, TRUE);
print_r($jsonResponse); die;
return $jsonResponse;
}
echo "\n";
echo "###########################################\n";
echo "Obtaining OAuth2 Access Token.... \n";
$url = $host.'/v1/oauth2/token';
$postArgs = 'grant_type=client_credentials';
$token = get_access_token($url,$postArgs);
echo "Got OAuth Token: ".$token;
echo "\n \n";
echo "###########################################\n";
echo "Initiating a Payment with PayPal Account... \n";
$url = $host.'/v1/payments/payouts';
$member_email = "test#test.com";
$data = array(
"sender_batch_header" => array(
"sender_batch_id" => '2542'.time(),
'email_subject' => 'Withdraw',
'email_message' => 'You have withdraw from asfd! Thanks for using our service!'
),
"items" => array(
array(
"recipient_type" => 'EMAIL',
'amount' => array(
'value' => 10.99,
'currency' => 'USD',
),
'note' => 'Thank You',
'sender_item_id' => 'A25426',
'receiver' => $member_email,
),
),
);
$data = json_encode($data);
$json_resp = make_post_call($url, $data);
foreach ($json_resp['links'] as $link) {
if($link['rel'] == 'execute'){
$payment_execute_url = $link['href'];
$payment_execute_method = $link['method'];
} else if($link['rel'] == 'approval_url'){
$payment_approval_url = $link['href'];
$payment_approval_method = $link['method'];
}
}
echo "Payment Created successfully: " . $json_resp['id'] ." with state '". $json_resp['state']."'\n\n";
echo "Please goto <a href='".$payment_approval_url."'>link</a> in your browser and approve the payment with a PayPal Account.\n";
Please help
Thank You

Related

How can I deregister a device if I only have that device's push token, not the HWID?

My database is only storing the push tokens for user devices, not the HWIDs.
Is it possible to use the Pushwoosh API to deregister a device with the push token only? It's not working when I send just the push token with an empty string for the hwid.
Here's my code:
$device_id = '';
$pushwoosh_push_token = 'Push-Token-here';
$pushwoosh_app_code = 'App-Code-here';
$pushwoosh_auth_token = 'Auth-Token-here';
$response = unregister_device_pushwoosh($device_id, $pushwoosh_push_token, $pushwoosh_app_code, $pushwoosh_auth_token);
print_r($response)."<br>";
function unregister_device_pushwoosh($device_id, $pushwoosh_push_token, $pushwoosh_app_code, $pushwoosh_auth_token) {
$url = 'https://cp.pushwoosh.com/json/1.3/unregisterDevice';
$data = array(
'request' => array(
'application' => $pushwoosh_app_code,
'push_token' => $pushwoosh_push_token,
'hwid' => $device_id,
),
);
$content = json_encode($data);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"Content-type: application/json\r\n".
"Authorization: Basic ".base64_encode("$pushwoosh_app_code:$pushwoosh_auth_token")
]);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if (200 != $status)
{
echo("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ', curl_errno ' . curl_errno($curl) . '<br>');
}
curl_close($curl);
return 'Response: ' . $json_response . "\n";
}

how can i generate ebay api token automatic

how to generate token ebay api automatic with php
i have try to make it with this :
<?php
$devID = '518664de-29b9-46e6-ba1b-63b3e4a93f18';
$appID = 'dropship-dropship-PRD-25b778b89-8248278e';
$certID = 'PRD-5b778b89c307-a516-45d6-b096-a310';
$devToken = "v^1.1#i^1#p^3#f^0#r^1#I^3#t^Ul4xMF8xOkQ1NzIxMUQ2NEFBRENGMTA2ODk0OEI1QkZGQjA3QkEyXzJfMSNFXjI2MA==";
$authCode = 'v%5E1.1%23i%5E1%23f%5E0%23r%5E1%23I%5E3%23p%5E3%23t%5EUl41Xzg6RDk3MEFCQjNDMDRENEE3NzIzOEE4NzExQUM1QTVEMDNfMF8xI0VeMjYw';
$ruName = "dropshipping-dropship-dropsh-okvoihtlt";
$scope = "https://api.ebay.com/oauth/api_scope https://api.ebay.com/oauth/api_scope/sell.marketing.readonly https://api.ebay.com/oauth/api_scope/sell.marketing https://api.ebay.com/oauth/api_scope/sell.inventory.readonly https://api.ebay.com/oauth/api_scope/sell.inventory https://api.ebay.com/oauth/api_scope/sell.account.readonly https://api.ebay.com/oauth/api_scope/sell.account https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly https://api.ebay.com/oauth/api_scope/sell.fulfillment https://api.ebay.com/oauth/api_scope/sell.analytics.readonly https://api.ebay.com/oauth/api_scope/sell.finances https://api.ebay.com/oauth/api_scope/sell.payment.dispute https://api.ebay.com/oauth/api_scope/commerce.identity.readonly https://api.ebay.com/oauth/api_scope/commerce.notification.subscription https://api.ebay.com/oauth/api_scope/commerce.notification.subscription.readonly";
$serverUrl = 'https://api.ebay.com/ws/api.dll';
$authToken = "";
$refreshToken = "";
$link = "https://api.ebay.com/identity/v1/oauth2/token";
$codeAuth = base64_encode($appID.':'.$certID);
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Authorization: Basic '.$codeAuth
));
// curl_setopt($ch, CURLHEADER_SEPARATE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=authorization_code&code=".urlencode($authCode)."&redirect_uri=".urlencode($ruName)."&scope=".urlencode($scope));
$response = curl_exec($ch);
$json = json_decode($response, true);
$info = curl_getinfo($ch);
curl_close($ch);
if($json != null)
{
echo "<pre>";
print_r($json);
echo "</pre>";
// echo $authToken = $json["access_token"];
// echo "<br><br>";
// echo $refreshToken = $json["refresh_token"];
}else {
echo 'no data in this';
}
and i show this =>
(
[error] => invalid_request
[error_description] => request is missing a required parameter or malformed.
)
so help me what is my problem and how can i fix it . thanks

CLIO return just on matter number by display number

Clio seems to have no solution but to ask it here.
So here I go.
I have the display number and I want to query the Matter ID.
This does not seem to be possible unless I do I x-bulk query the loop throw the results.
Does anyone have a simple query to do this?
here is what I have for PHP so far.
function matter_one ( $token,$refresh_toke ) {
$header = 'Authorization: bearer '.$token."\r\n";
//echo $header."\r\n";
$offset = 0;
$url = 'https://app.clio.com/api/v4/matters.json?&fields=id,description,display_number';
//echo $url."\r\n";
$ch = curl_init();
//curl_setopt($ch, CURLOPT_VERBOSE, true); //used for trouble shooting.
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$resp = curl_exec($ch);
print "curl response is:" . $resp;
die();
There is a better way, use
https://app.clio.com/api/v4/matters?fields=id,display_number&query=100140
you will need to loop and check the display number does actualy match as 100140 and 100140B and 10014000 would be returned also.
If the issue is you do not want to do the x-bulk here is code that will pull all the info, you can either modify the code to find the item in the data returned for each page or find in the final array.
function performListRequestAllMatters()
{
$header = 'Authorization: bearer ' . $this->token;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->base . $this->API_version . 'matters' . '?fields=id,display_number');
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if (!$response) {
die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
} elseif (200 != curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
echo "Bad Response Code!";
echo "\n";
echo "Response HTTP Status Code : " . curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "\n";
echo "Response HTTP Body : " . $response;
} else {
$json = json_decode($response, true);
$list = $json['data'];
while (isset($json['meta']['paging']['next'])) {
// process a new request until all pages have been retrieved
curl_setopt($ch, CURLOPT_URL, $json['meta']['paging']['next']);
$response = curl_exec($ch);
$json = json_decode($response, true);
$newList = $json['data'];
$list = array_merge($list, $newList);
}
}
curl_close($ch);
return $list;
}
if have 10,000 plus records you have to use bulk.
this function works great at getting all the records.
Then you can find what ever number you need.
function matter_ID_display ( $token,$refresh_toke ) {
// this returns all the matter ID and display name
//adding X-BULK
$header = 'Authorization: bearer '.$token."\r\n"."X-BULK: true";
//echo $header."\r\n";
$offset = 0;
$url = 'https://app.clio.com/api/v4/matters.json?offset='.$offset.'&fields=id,display_number';
$cookie_jar = 'C:\Sites\Project for simmons and flecter\PHP\tmp\cookies.txt';
$cookie_jar2 = 'C:\Sites\Project for simmons and flecter\PHP\tmp\cookies2.txt';
//echo $url."\r\n";
$ch = curl_init();
//curl_setopt($ch, CURLOPT_VERBOSE, true); //used for trouble shooting.
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$resp = curl_exec($ch);
//print "curl response is:" . $resp;
if( !$resp ) {
die('Error: "' . curl_error( $ch ) . '" - Code: ' . curl_errno( $ch ) );
}
else if ( 200 != curl_getinfo( $ch, CURLINFO_HTTP_CODE ) ) {
echo "Expected code 202";
echo "\n";
echo "Response HTTP Status Code : " . curl_getinfo( $ch, CURLINFO_HTTP_CODE );
echo "\n";
//echo "Response HTTP Body : " . $resp;
}
//$resp = json_encode($resp);
$headers = get_headers_from_curl_response($resp);
//$headers = json_encode($headers);
//print_r ($headers);
$url = $headers["Location"];
echo "url for getting the bulk data\r\n";
echo $url."\r\n";
echo "\n";
curl_close($ch);
//sleep for x seconds
//have to sleep due to processing at clio
$seconds = 20;
echo "Sleeping for ".$seconds." seconds\r\n";
sleep($seconds);
echo "\n";
// seperate curl_
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_COOKIEJAR => $cookie_jar2,
CURLOPT_COOKIEFILE=> $cookie_jar2,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array("authorization: Bearer ".$token),
CURLOPT_SSL_VERIFYPEER => false, // Disabled SSL Cert checks
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_RETURNTRANSFER => true, // return web page
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo 'Curled first time';
echo "\n";
// have to curl two times one without authorization
echo "\n";
Echo "cURL repeat";
echo "\n";
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_COOKIEJAR => $cookie_jar2,
CURLOPT_COOKIEFILE=> $cookie_jar2,
CURLOPT_CUSTOMREQUEST => "GET",
//CURLOPT_HTTPHEADER => array("authorization: Bearer ".$token),
CURLOPT_SSL_VERIFYPEER => false, // Disabled SSL Cert checks
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_RETURNTRANSFER => true, // return web page
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else
{echo 'Good Reponse from Curl second time';
echo "\n";}
}
$response_Decode = json_decode($response);
//print_r ($response_Decode);
// got the data. Now just need to turn to a clean array and save to file.
//die('Before Array clean up');
//clean and make into an array
$response_Decode=$response_Decode->data;
$response_Decode=$response_Decode[0];
//print_r ($response_Decode);
//die(); //For testing
$matter_array = array();
if(!empty($response_Decode->data) && is_array($response_Decode->data)) {
foreach ($response_Decode->data as $info) {
$d = array();
$d[] = $info->display_number;
$d[] = $info->id;
$matter_array[] = $d;
}
}
print_r($matter_array); //For testing
die(); //For testing
//matter_array is a full array of all matter ID and Matter Display numbers
return $matter_array; }

Website form data stop saving into Google spreadsheet from yesterday i.e 26/05/2015

I have created an application where my website form data will be stored into a google spreadsheet. It was working fine till yesterday i.e 26/05/2015. But from today i.e 27/05/2015 it suddenly stopped working. And no value is adding into the google spreadsheet.
I have used the below mentioned class for spreadsheet application
spreadsheet.php:
<?php
class spreadsheet {
private $token;
private $spreadsheet;
private $worksheet;
private $spreadsheetid;
private $worksheetid;
public function __construct() {
}
public function authenticate($username, $password) {
$url = "https://www.google.com/accounts/ClientLogin";
$fields = array(
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => $username,
"Passwd" => $password,
"service" => "wise",
"source" => "pfbc"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if($status == 200) {
if(stripos($response, "auth=") !== false) {
preg_match("/auth=([a-z0-9_\-]+)/i", $response, $matches);
$this->token = $matches[1];
}
}
}
public function setSpreadsheet($title) {
$this->spreadsheet = $title;
}
public function setWorksheet($title) {
$this->worksheet = $title;
}
public function add($data) {
if(!empty($this->token)) {
$url = $this->getPostUrl();
if(!empty($url)) {
$headers = array(
"Content-Type: application/atom+xml",
"Authorization: GoogleLogin auth=" . $this->token,
"GData-Version: 3.0"
);
$columnIDs = $this->getColumnIDs();
if($columnIDs) {
$fields = '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">';
foreach($data as $key => $value) {
$key = $this->formatColumnID($key);
if(in_array($key, $columnIDs))
$fields .= "<gsx:$key><![CDATA[$value]]></gsx:$key>";
}
$fields .= '</entry>';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
}
}
}
}
private function getColumnIDs() {
$url = "https://spreadsheets.google.com/feeds/cells/" . $this->spreadsheetid . "/" . $this->worksheetid . "/private/full?max-row=1";
$headers = array(
"Authorization: GoogleLogin auth=" . $this->token,
"GData-Version: 3.0"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if($status == 200) {
$columnIDs = array();
$xml = simplexml_load_string($response);
if($xml->entry) {
$columnSize = sizeof($xml->entry);
for($c = 0; $c < $columnSize; ++$c)
$columnIDs[] = $this->formatColumnID($xml->entry[$c]->content);
}
return $columnIDs;
}
return "";
}
private function getPostUrl() {
$url = "https://spreadsheets.google.com/feeds/spreadsheets/private/full?title=" . urlencode($this->spreadsheet);
$headers = array(
"Authorization: GoogleLogin auth=" . $this->token,
"GData-Version: 3.0"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($status == 200) {
$spreadsheetXml = simplexml_load_string($response);
if($spreadsheetXml->entry) {
$this->spreadsheetid = basename(trim($spreadsheetXml->entry[0]->id));
$url = "https://spreadsheets.google.com/feeds/worksheets/" . $this->spreadsheetid . "/private/full";
if(!empty($this->worksheet))
$url .= "?title=" . $this->worksheet;
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($status == 200) {
$worksheetXml = simplexml_load_string($response);
if($worksheetXml->entry)
$this->worksheetid = basename(trim($worksheetXml->entry[0]->id));
}
}
}
curl_close($curl);
if(!empty($this->spreadsheetid) && !empty($this->worksheetid))
return "https://spreadsheets.google.com/feeds/list/" . $this->spreadsheetid . "/" . $this->worksheetid . "/private/full";
return "";
}
private function formatColumnID($val) {
return preg_replace("/[^a-zA-Z0-9.-]/", "", strtolower($val));
}
}
?>
and use it in following way:
include 'spreadsheet.php';
$doc = new spreadsheet();
$doc->authenticate("example#example.com", "example");
$doc->setSpreadsheet("Tester");
$doc->setWorksheet("Sheet1");
$my_data = array("First Name" => "John", "Last Name" => "Doe");
$doc->add($my_data);
Please help me out. Thanks in advance.
The ClientLogin method, which has been deprecated for a number of years, has now been turned off. It will return a 404 when trying to authenticate. You will need to migrate to OAuth for authentication.
See https://developers.google.com/identity/protocols/AuthForInstalledApps
Here is an updated PHP library that uses OAuth - https://github.com/asimlqt/php-google-spreadsheet-client. The author also has a sample project with instructions to generate OAuth access tokens.

Docusign - Send an email to embedded signer

I'm using the embedded Docusign API to embed a document for signing. I store first name, last name, and email in a SESSION from the form before. I've tried to change the email in templateRoles to be the email that is stored in the SESSION from the form, but I either time out or get an error that the email is not the correct:
"templateRoles" => array(
array( "roleName" => $templateRoleName, "email" => $email, "name" => $recipientName, "clientUserId" => $clientUserId )),
I'm using PHP. Any help is appreciated. I need to send an email to the embedded signer with the completed form, if it is even possible, once the signing is complete.
Thanks!
EDIT Full Call
session_start();
$results = array();
foreach($_SESSION['forms'] as $row){
$results[] = $row;
}
$first_name = $results[0];
$last_name = $results[1];
$email2 = $results[2];
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 1 - Login (retrieves baseUrl and accountId)
/////////////////////////////////////////////////////////////////////////////////////////////////
$url = "https://www.docusign.net/restapi/v2/login_information";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("X-DocuSign-Authentication: $header"));
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 200 ) {
echo "error calling (condition 1) webservice, status is:" . $status;
exit(-1);
}
$response = json_decode($json_response, true);
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
$headers = curl_getinfo($curl, CURLINFO_HEADER_OUT);
curl_close($curl);
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 2 - Create an envelope with an Embedded recipient (uses the clientUserId property)
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("accountId" => $accountId,
"emailSubject" => "Document",
"templateId" => $templateId,
"templateRoles" => array(
array( "roleName" => $templateRoleName, "email" => $email2, "name" => $recipientName, "clientUserId" => $clientUserId )),
"status" => "sent");
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
echo "error calling (condition 2) webservice, status is:" . $status . "<br>\nerror text is --> ";
print_r($json_response); echo "<br>\n";
exit(-1);
}
$headers = curl_getinfo($curl, CURLINFO_HEADER_OUT);
$response = json_decode($json_response, true);
$envelopeId = $response["envelopeId"];
curl_close($curl);
/////////////////////////////////////////////////////////////////////////////////////////////////
// STEP 3 - Get the Embedded Signing View
/////////////////////////////////////////////////////////////////////////////////////////////////
$data = array("returnUrl" => "http://www.theURL.com/docusign/thank-you",
"authenticationMethod" => "None", "email" => $email,
"userName" => $recipientName, "clientUserId" => $clientUserId
);
$data_string = json_encode($data);
$curl = curl_init($baseUrl . "/envelopes/$envelopeId/views/recipient" );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string),
"X-DocuSign-Authentication: $header" )
);
$json_response = curl_exec($curl);
$status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ( $status != 201 ) {
echo "error calling webservice (condition 3), status is:" . $status . "\nerror text is --> ";
print_r($json_response); echo "\n";
exit(-1);
}
$headers = curl_getinfo($curl, CURLINFO_HEADER_OUT);
$response = json_decode($json_response, true);
$url = $response["url"];
if ( $detect->isMobile() ) {
echo "<p style='color:white;'>Click to Sign the Consent Form on your mobile device:</p>";
echo "<a href='$url' style='width:100%; padding: 10px 20px; border: 3px solid white; color: white;'>Sign eConsent Form</a>";
} else {
echo "<iframe src='$url' style='width:100%; height:100%; min-height: 800px;overflow:scroll;'></iframe>";
}
The authorization is in another file with templateID, email and password, clientID, etc.
You'll want to enable a setting on your account when you log in as the administrator.
Preferences > Features > Use Envelope Complete Email for (non-suppressed) Embedded Signers

Categories