{"title":"Start Alipay and WeChat Pay transactions","category":"default","creationDate":1776961627,"content":"<h2 id=\"prototype-the-callback\">Prototype the callback<\/h2>\n<p>Prototype the\u00a0<code>create_new_tender_CB<\/code>\u00a0and pass this as a parameter of the function pointer to the\u00a0<code>create_special_tender<\/code>\u00a0call.\u00a0<\/p>\n<h3 id=\"code-example\">Code example<\/h3>\n<p>The callback function declaration is:<\/p>\n<pre><code class=\"language-cpp\">void create_new_tender_CB(create_tender_response *response, void *echo_struct){\n    app_context_t *sPOS = (app_context_t *)echo_struct;\nif (response-&gt;tender_reference) {\n        safe_strdup(&amp;sPOS-&gt;tender_reference, response-&gt;tender_reference);\n        sPOS-&gt;pending_callback = 0; \/\/mark ok......\n    } else {\n        sPOS-&gt;pending_callback = -1;\n}<\/code><\/pre>\n<h2 id=\"allocate-and-populate-request-structure\">Allocate and populate request structure<\/h2>\n<p>Use <code>create_special_tender_request<\/code>\u00a0to allocate memory for an\u00a0<code>special_tender_request<\/code>\u00a0structure.\u00a0Populate the request by performing\u00a0string duplication and filling heap allocated strings. If you want the data for later use, retain it, or it will be released automatically.<\/p>\n<pre><code class=\"language-cpp\">special_tender_request *request = create_special_tender_request();\n    if (request) {\n         request-&gt;reference = strdup(\"Simple transaction\");\n         request-&gt;merchant_account = strdup(sPOS-&gt;merchant_account);\n         request-&gt;terminal_id = strdup(sPOS-&gt;terminal_id);\n         request-&gt;amount_currency = strdup(sPOS-&gt;currency);\n         request-&gt;amount_value = sPOS-&gt;amount;\n         request-&gt;transaction_type = strdup(\"payment\");\n         request-&gt;payment_method_type = strdup(\"alipay\");\n\u00a0<\/code><\/pre>\n<h2 id=\"add-and-remove-special-options\">Add and remove special options<\/h2>\n<p>Special options are dictionary key value pairs. This information is passed directly to the PED, which interprets it.<\/p>\n<p>Use\u00a0<code>special_tender_add_option<\/code>\u00a0to set\u00a0 special options, passing the request along with key value pairs. Use\u00a0<code>special_tender_rm_option<\/code>\u00a0to remove the set options.<\/p>\n<h2 id=\"call-the-create_special_tender-function\">Call the create_special_tender Function<\/h2>\n<p>Call the\u00a0<code>create_special_tender<\/code>\u00a0function to\u00a0Initiate the sale transaction, which triggers any relevant callbacks,\u00a0and pass in the request that was previously allocated.<\/p>\n<p>The POS waits for the final state and the\u00a0\u00a0<code>status_tender_final<\/code>\u00a0\u00a0callback to report the final result of the transaction, even if a cancel request has been issued. The reason for this is that the transaction might already be in a state in which a cancel is not possible.<\/p>\n<p>The sale transaction includes the merchant account information, as this is used to register PEDs for multiple merchant accounts, and transactions can be performed on more than one of these merchant accounts.<\/p>\n<h2 id=\"parameters\">Parameters<\/h2>\n<table>\n<thead>\n<tr>\n<th>Value<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>request<\/code><\/td>\n<td>Pointer to the <code>special_tender_request<\/code> struct, this struct contains all the input parameters for this call.<\/td>\n<\/tr>\n<tr>\n<td><code>create_new_tender_CB<\/code><\/td>\n<td>Pointer to the callback function in the POS that will be called with the results of the create special tender call<\/td>\n<\/tr>\n<tr>\n<td><code>echo_struct<\/code><\/td>\n<td>Pointer to a POS defined struct. Returned in the callback. It can be used to share a POS data struct between the call to the library and the callback from the library.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"code-example-1\">Code example<\/h3>\n<p>The declaration of the call to start a transaction is as follows:<\/p>\n<pre><code class=\"language-cpp\">result = create_special_tender(request, create_new_tender_CB, sPOS);<\/code><\/pre>\n<h2 id=\"handle-the-callback\">Handle the callback<\/h2>\n<p>Handle the <code>create_new_tender_CB<\/code> to check if the transaction was accepted by the terminal by checking if <code>tender_reference<\/code> was populated by the library.\u00a0<\/p>\n<pre><code class=\"language-cpp\"> if (response-&gt;tender_reference) {\n  safe_strdup(&amp;sPOS-&gt;tender_reference, response-&gt;tender_reference);\n  sPOS-&gt;pending_callback = 0; \/\/mark ok......\n } else {\n  sPOS-&gt;pending_callback = -1;\n }<\/code><\/pre>\n<p>Check the result by getting information from the <code>create_tender_response<\/code>.<\/p>\n<p>The POS needs to wait for the\u00a0<code>create_new_tender_CB<\/code>\u00a0to happen, before it can continue with other functions.\u00a0 After the\u00a0<code>create_new_tender_CB<\/code>\u00a0is returned, the system returns a number of other callbacks. Finally, the system returns the\u00a0final\u00a0callback that contains the final transaction result. Another transaction can only be started when the final transaction result is received.<\/p>\n<h3 id=\"parameters-1\">Parameters<\/h3>\n<table>\n<thead>\n<tr>\n<th>Data element<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>create_tender_response<\/code><\/td>\n<td>A unique reference for the transaction that is generated by the PED device. This reference is used for subsequent actions on the transaction. For a list of parameters, see <code>create_tender_response<\/code>.<\/td>\n<\/tr>\n<tr>\n<td><code>echo_struct<\/code><\/td>\n<td>Pointer to a user-defined struct. Returned in the callback. It can be used to share a POS data struct between the call to the library and the callback from the library in response to the call.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"sc-notice note\"><div>\n<p>The <code>create_new_tender_CB<\/code> is a callback to the creation of a tender, but does not represent the status or result of the transaction. The result is returned in <code>tender_finished_CB<\/code>.<\/p>\n<\/div><\/div>","url":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/extras-c-library\/start-alipay-and-wechat-pay-transactions-c","articleFields":{"id":"34116793","type":"page","_expandable":{"operations":""},"status":"current"},"algolia":{"url":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/extras-c-library\/start-alipay-and-wechat-pay-transactions-c","title":"Start Alipay and WeChat Pay transactions","content":"Prototype the callback\nPrototype the\u00a0create_new_tender_CB\u00a0and pass this as a parameter of the function pointer to the\u00a0create_special_tender\u00a0call.\u00a0\nCode example\nThe callback function declaration is:\nvoid create_new_tender_CB(create_tender_response *response, void *echo_struct){\n    app_context_t *sPOS = (app_context_t *)echo_struct;\nif (response-&gt;tender_reference) {\n        safe_strdup(&amp;sPOS-&gt;tender_reference, response-&gt;tender_reference);\n        sPOS-&gt;pending_callback = 0; \/\/mark ok......\n    } else {\n        sPOS-&gt;pending_callback = -1;\n}\nAllocate and populate request structure\nUse create_special_tender_request\u00a0to allocate memory for an\u00a0special_tender_request\u00a0structure.\u00a0Populate the request by performing\u00a0string duplication and filling heap allocated strings. If you want the data for later use, retain it, or it will be released automatically.\nspecial_tender_request *request = create_special_tender_request();\n    if (request) {\n         request-&gt;reference = strdup(\"Simple transaction\");\n         request-&gt;merchant_account = strdup(sPOS-&gt;merchant_account);\n         request-&gt;terminal_id = strdup(sPOS-&gt;terminal_id);\n         request-&gt;amount_currency = strdup(sPOS-&gt;currency);\n         request-&gt;amount_value = sPOS-&gt;amount;\n         request-&gt;transaction_type = strdup(\"payment\");\n         request-&gt;payment_method_type = strdup(\"alipay\");\n\u00a0\nAdd and remove special options\nSpecial options are dictionary key value pairs. This information is passed directly to the PED, which interprets it.\nUse\u00a0special_tender_add_option\u00a0to set\u00a0 special options, passing the request along with key value pairs. Use\u00a0special_tender_rm_option\u00a0to remove the set options.\nCall the create_special_tender Function\nCall the\u00a0create_special_tender\u00a0function to\u00a0Initiate the sale transaction, which triggers any relevant callbacks,\u00a0and pass in the request that was previously allocated.\nThe POS waits for the final state and the\u00a0\u00a0status_tender_final\u00a0\u00a0callback to report the final result of the transaction, even if a cancel request has been issued. The reason for this is that the transaction might already be in a state in which a cancel is not possible.\nThe sale transaction includes the merchant account information, as this is used to register PEDs for multiple merchant accounts, and transactions can be performed on more than one of these merchant accounts.\nParameters\n\n\n\nValue\nDescription\n\n\n\n\nrequest\nPointer to the special_tender_request struct, this struct contains all the input parameters for this call.\n\n\ncreate_new_tender_CB\nPointer to the callback function in the POS that will be called with the results of the create special tender call\n\n\necho_struct\nPointer to a POS defined struct. Returned in the callback. It can be used to share a POS data struct between the call to the library and the callback from the library.\n\n\n\nCode example\nThe declaration of the call to start a transaction is as follows:\nresult = create_special_tender(request, create_new_tender_CB, sPOS);\nHandle the callback\nHandle the create_new_tender_CB to check if the transaction was accepted by the terminal by checking if tender_reference was populated by the library.\u00a0\n if (response-&gt;tender_reference) {\n  safe_strdup(&amp;sPOS-&gt;tender_reference, response-&gt;tender_reference);\n  sPOS-&gt;pending_callback = 0; \/\/mark ok......\n } else {\n  sPOS-&gt;pending_callback = -1;\n }\nCheck the result by getting information from the create_tender_response.\nThe POS needs to wait for the\u00a0create_new_tender_CB\u00a0to happen, before it can continue with other functions.\u00a0 After the\u00a0create_new_tender_CB\u00a0is returned, the system returns a number of other callbacks. Finally, the system returns the\u00a0final\u00a0callback that contains the final transaction result. Another transaction can only be started when the final transaction result is received.\nParameters\n\n\n\nData element\nDescription\n\n\n\n\ncreate_tender_response\nA unique reference for the transaction that is generated by the PED device. This reference is used for subsequent actions on the transaction. For a list of parameters, see create_tender_response.\n\n\necho_struct\nPointer to a user-defined struct. Returned in the callback. It can be used to share a POS data struct between the call to the library and the callback from the library in response to the call.\n\n\n\n\nThe create_new_tender_CB is a callback to the creation of a tender, but does not represent the status or result of the transaction. The result is returned in tender_finished_CB.\n","type":"page","locale":"pt","boost":14,"hierarchy":{"lvl0":"Home","lvl1":"Terminais","lvl2":"Deprecation of classic libraries","lvl3":"Library integrations","lvl4":"C library integration","lvl5":"Extras","lvl6":"Start Alipay and WeChat Pay transactions"},"hierarchy_url":{"lvl0":"https:\/\/docs.adyen.com\/pt","lvl1":"https:\/\/docs.adyen.com\/pt\/point-of-sale","lvl2":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation","lvl3":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations","lvl4":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration","lvl5":"https:\/\/docs.adyen.com\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/extras-c-library","lvl6":"\/pt\/point-of-sale\/classic-library-deprecation\/classic-library-integrations\/c-library-integration\/extras-c-library\/start-alipay-and-wechat-pay-transactions-c"},"levels":7,"category":"In-person payments","category_color":"green","tags":["Start","Alipay","WeChat","transactions"]}}
