how to integrate Assently api for e-signature transaction in PHP
Asked Answered
B

1

26

In my wp project, I am using Assently for e-signature implementation. Though I have an account and created a pdf form file to be filled by the user I just am not able to proceed a bit. I am finding documentation not clear. Also, I am not clear about what needs to be done so that the user will be shown form to process the transaction.

So, any help/suggestions to proceed forward is appreciated.

I have tried the following based on assently-laravel. But it's asking me to login. What is an error here? Code:

define('ASSENTLY_DEBUG', true);
define('ASSENTLY_KEY', 'key');
define('ASSENTLY_SECRET', 'secret-generated');

include_once('assently/Assently.php');
$assently = new Assently();
$assently->authenticate(ASSENTLY_KEY, ASSENTLY_SECRET);

$url = 'https://test.assently.com/api/v2/createcasefromtemplate';
$default = array(
    'Id' => '5a0e0869-' . rand(1111, 9999) . '-4b79-' . rand(1111, 9999) . '-466ea5cca5ce'
);
$data = array(
    'auth' => $assently->auth(),
    'templateId'    => '0e004e2b-b192-4ce2-8f47-d7a4576d7df6',
    'newCaseId'     => '5a0e0869-' . rand(1111, 9999) . '-4b79-' . rand(1111, 9999) . '-466ea5cca5ce',
    'agentUsername' => ''
);

$data = array(
    'json' => $data
);
$options = array(
    'http' => array(
        'header'  => "Content-type: application/json; charset=utf-8\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo '<pre>';
print_r($result);
die;
Bagging answered 10/10, 2017 at 10:25 Comment(7)
test.assently.com/api#communication What is unclear?Differentiation
@Differentiation I am not able to understand how to show pdf fillable form on click and then complete the whole transaction.Bagging
@Differentiation can you provide some codes on how to do it or guide me here.Bagging
I think it's best to ask a new question and provide some more details. If you want to know how to show a form based on on-click, you should start there. It's good to know that I don't know anything about Assently ;-)Differentiation
you are not sending the authentication in your request. You authenticated but no authentication sent in your request. check it onceIslamite
try removing auth from top data array and put it with json data array. $data = array( 'json' => $data, 'auth' => $assently->auth() );Islamite
@RKJ no it's not working :(Bagging
I
1

create this class inside assently folder

use Assently\AssentlyCase;
use Exception;

class  CustomAssentlyCase extends AssentlyCase 
{
    public function createFromTemplate($data)
    {
        $default = [
            'newCaseId' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce'
        ];

        $json = array_merge($default, $data);

        try{
            $response = $this->client->post($this->url('createcasefromtemplate'), [
                'auth' => $this->assently->auth(),
                'json' => $json
            ]);

        }catch(Exception $e){
            print_r($e->getMessage());
        }
        return $response;
    }
}

Use

define('ASSENTLY_DEBUG', true);
define('ASSENTLY_KEY', 'key');
define('ASSENTLY_SECRET', 'secret-generated');

include_once('assently/Assently.php');
include_once('assently/CustomAssentlyCase.php');
$assently = new Assently();
$assently->authenticate(ASSENTLY_KEY, ASSENTLY_SECRET);

$data = array(
    'templateId' => '0e004e2b-b192-4ce2-8f47-d7a4576d7df6',
    'newCaseId' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce',
    'agentUsername' => 'agentUsername' // PUT your agent username here it is required
);

$customAssentlyCase = new CustomAssentlyCase($assently);
$result = $customAssentlyCase->createFromTemplate($data);
print_r($result);

Try this, though not tested but should work. Good luck.

Islamite answered 17/11, 2017 at 8:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.