Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we add Payment Item field in document? #227

Open
mihir8400 opened this issue Aug 6, 2024 · 1 comment
Open

How can we add Payment Item field in document? #227

mihir8400 opened this issue Aug 6, 2024 · 1 comment

Comments

@mihir8400
Copy link

mihir8400 commented Aug 6, 2024

Hello,
How can we add a Payment Item Field in the document?

fieldtypes2

in the above Image, they provide payment item fields.

using below code

` $this->authenticate();

    $envelopeApi = new EnvelopesApi($this->apiClient);

    $document = new Document([
        'document_base64' => base64_encode(file_get_contents($documentPath)),
        'name' => 'myDoc.pdf',
        'file_extension' => 'pdf',
        'document_id' => '1'
    ]);

    $signHere = new SignHere([
        'document_id' => '1',
        'page_number' => '9',
        'x_position' => '200',
        'y_position' => '200'
    ]);
     $nameTab = new \DocuSign\eSign\Model\Text([
        'document_id' => '1',
        'page_number' => '9',
        'x_position' => '200',
        'y_position' => '255',
        'tab_label' => 'Printed Name',
        'value' => $recipientName,
        'font' => 'helvetica',
        'font_size' => 'Size12',
        'bold' => 'false',
        'italic' => 'false',
        'underline' => 'false',
        'font_color' => 'Black'
    ]);
     $tabs = new Tabs([
        'sign_here_tabs' => [$signHere],
        'text_tabs' => [$nameTab]
    ]);

$signer = new Signer([
'email' => $recipientEmail,
'name' => $recipientName,
'recipient_id' => '1',
'tabs' => $tabs,
'client_user_id' => $token
]);

    $envelopeDefinition = new EnvelopeDefinition([
        'email_subject' => 'Please sign document',
        'documents' => [$document],
        'recipients' => ['signers' => [$signer]],
        'status' => 'sent'
    ]);

        $result = $envelopeApi->createEnvelope($this->accountId, $envelopeDefinition);

`

I put the signed and name field in a document.
now How can we add a Payment Item Field in the document like a text field and signed field?
I want only to save the credit card details of the signer. stripe Payment method

@rafaykhan-DocuSign
Copy link

I understand you're looking to add a payment field within your document. With using PHP, we do have an article that does frame the steps in obtaining this field.

This guide provides a comprehensive overview of utilizing DocuSign Payments to facilitate payment collection through envelopes. It outlines the steps required to configure a payment gateway for processing payments from signers. Additionally, it details the procedure for collecting online credit card payments via an order form sent within an envelope. For testing purposes, you may use one of the test credit cards supplied by Stripe.

The article below shares code samples of how you can create the field.
https://developers.docusign.com/docs/esign-rest-api/how-to/request-a-payment/

This is the code sample:
$envelope_definition = CollectPaymentService::makeEnvelope($args["envelope_args"], $demoDocsPath);
public static function makeEnvelope(array $args, $demoDocsPath): EnvelopeDefinition
{

Order form constants

$l1_name = "Harmonica";
$l1_price = 5;
$l1_description = "$l1_price each";
$l2_name = "Xylophone";
$l2_price = 150;
$l2_description = "$l2_price each";
$currency_multiplier = 100;

read the html file from a local directory

The read could raise an exception if the file is not available!

$doc1_file = 'order_form.html';
$doc1_html_v1 = file_get_contents($demoDocsPath . $doc1_file);

Substitute values into the HTML

Substitute for: {signerName}, {signerEmail}, {cc_name}, {cc_email}

$doc1_html_v2 = str_replace(
['{signer_email}' , '{cc_name}' , '{cc_email}' ],
[$args['signer_email'], $args['cc_name'], $args['cc_email']],
$doc1_html_v1
);

create the envelope definition

$envelope_definition = new EnvelopeDefinition([
'email_subject' => 'Please complete your order',
'status' => 'sent']);

add the document

$doc1_b64 = base64_encode($doc1_html_v2);
$doc1 = new Document([
'document_base64' => $doc1_b64,
'name' => 'Order form', # can be different from actual file name
'file_extension' => 'html', # Source data format.
'document_id' => '1' # a label used to reference the doc
]);
$envelope_definition->setDocuments([$doc1]);

create a signer recipient to sign the document

$signer1 = new Signer([
'email' => $args['signer_email'], 'name' => $args['signer_name'],
'recipient_id' => "1", 'routing_order' => "1"]);

create a cc recipient to receive a copy of the documents

$cc1 = new CarbonCopy([
'email' => $args['cc_email'], 'name' => $args['cc_name'],
'recipient_id' => "2", 'routing_order' => "2"]);

Create signHere fields (also known as tabs) on the documents,

We're using anchor (autoPlace) positioning

$sign_here1 = new SignHere([
'anchor_string' => '/sn1/',
'anchor_y_offset' => '10', 'anchor_units' => 'pixels',
'anchor_x_offset' => '20']);

$list1 = new ModelList([
'font' => "helvetica",
'font_size' => "size11",
'anchor_string' => '/l1q/',
'anchor_y_offset' => '-10', 'anchor_units' => 'pixels',
'anchor_x_offset' => '0',
'list_items' => [
['text' => "1" , 'value' => "1" ], ['text' => "2", 'value' => "2"],
['text' => "3", 'value' => "3"], ['text' => "4" , 'value' => "4" ],
['text' => "5" , 'value' => "5" ], ['text' => "6", 'value' => "6"]
],
'required' => "true",
'tab_label' => "l1q"
]);

$list2 = new ModelList([
'font' => "helvetica",
'font_size' => "size11",
'anchor_string' => '/l2q/',
'anchor_y_offset' => '-10', 'anchor_units' => 'pixels',
'anchor_x_offset' => '0',
'list_items' => [
['text' => "1" , 'value' => "1" ], ['text' => "2", 'value' => "2"],
['text' => "3", 'value' => "3"], ['text' => "4" , 'value' => "4" ],
['text' => "5" , 'value' => "5" ], ['text' => "6", 'value' => "6"]
],
'required' => "true",
'tab_label' => "l2q"
]);

create two formula tabs for the extended price on the line items

$formulal1e = new FormulaTab([
'font' => "helvetica",
'font_size' => "size11",
'anchor_string' => '/l1e/',
'anchor_y_offset' => '-8', 'anchor_units' => 'pixels',
'anchor_x_offset' => '105',
'tab_label' => "l1e",
'formula' => "[l1q] * $l1_price",
'round_decimal_places' => "0",
'required' => "true",
'locked' => "true",
'disable_auto_size' => "false",
]);
$formulal2e = new FormulaTab([
'font' => "helvetica",
'font_size' => "size11",
'anchor_string' => '/l2e/',
'anchor_y_offset' => '-8', 'anchor_units' => 'pixels',
'anchor_x_offset' => '105',
'tab_label' => "l2e",
'formula' => "[l2q] * $l2_price",
'round_decimal_places' => "0",
'required' => "true",
'locked' => "true",
'disable_auto_size' => "false",
]);

Formula for the total

$formulal3t = new FormulaTab([
'font' => "helvetica",
'bold' => "true",
'font_size' => "size12",
'anchor_string' => '/l3t/',
'anchor_y_offset' => '-8', 'anchor_units' => 'pixels',
'anchor_x_offset' => '50',
'tab_label' => "l3t",
'formula' => '[l1e] + [l2e]',
'round_decimal_places' => "0",
'required' => "true",
'locked' => "true",
'disable_auto_size' => "false",
]);

Payment line items

$payment_line_iteml1 = new PaymentLineItem([
'name' => $l1_name, 'description' => $l1_description,
'amount_reference' => "l1e"]);
$payment_line_iteml2 = new PaymentLineItem([
'name' => $l2_name, 'description' => $l2_description,
'amount_reference' => "l2e"]);
$payment_details = new PaymentDetails([
'gateway_account_id' => $args['gateway_account_id'],
'currency_code' => "USD",
'gateway_name' => $args['gateway_name'],
'line_items' => [$payment_line_iteml1, $payment_line_iteml2]]);

Hidden formula for the payment itself

$formula_payment = new FormulaTab([
'tab_label' => "payment",
'formula' => "([l1e] + [l2e]) * $currency_multiplier",
'round_decimal_places' => "0",
'payment_details' => $payment_details,
'hidden' => "true",
'required' => "true",
'locked' => "true",
'document_id' => "1",
'page_number' => "1",
'x_position' => "0",
'y_position' => "0"]);

Tabs are set per recipient / signer

$signer1_tabs = new Tabs([
'sign_here_tabs' => [$sign_here1],
'list_tabs' => [$list1, $list2],
'formula_tabs' => [$formulal1e, $formulal2e,
$formulal3t, $formula_payment]]);
$signer1->setTabs($signer1_tabs);

Add the recipients to the envelope object

$recipients = new Recipients([
'signers' => [$signer1], 'carbon_copies' => [$cc1]]);
$envelope_definition->setRecipients($recipients);

return $envelope_definition;
}

Best,
DocuSign Support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants