---
title: Automatic Key Exchange
url: amazon-pay-registration/automatickeyexchange.html
---

When a merchant has initiated the Amazon Pay registration process, a URL should be available to
receive an encrypted object containing the merchant’s credentials, after the completion of registration
and setup. This URL is passed to Amazon Pay in the initiating post as the **keyShareURL**. When a
merchant has finished the registration process, they will be prompted to transfer keys, and this triggers
an HTTP POST to the **keyShareURL**. The encrypted credential payload will be passed via an HTTP POST
payload parameter, and will be a JSON string. To see an example of the encrypted payload, see the
[Payload data structures](payload.html) section.

After receiving the encrypted payload, you need to follow the instructions in the [How to decrypt
credentials](decryption.html) section to successfully decrypt the underlying merchant
credentials.


## keyShareURL functionality

There are two requirements for the response served by the **keyShareURL** back to Amazon. After
processing the request, the response MUST:

<ul>
	<li>Properly set the following CORS headers:
		<ul>
			<li>Access Control Allow Origin: https://payments.amazon.com</li>
			<li>Access Control Allow Methods: GET, POST</li>
			<li>Access Control Allow Headers: Content Type</li>
		</ul>
	</li>
	<li>Respond to the <strong>keyShareURL</strong> request with the following:</li>
	<ul>
		<li>If processing the payload is successful:
			<ul>
				<li>200 http response</li>
				<li> JSON object in the body
					<pre><code>{‘result’: ‘success’}</code></pre>
				</li>
			</ul>
		</li>
		<li>If processing the payload is unsuccessful:
			<ul>
				<li>400 http response</li>
				<li>JSON object in the body
					<pre><code>{‘result’: ‘error’, ‘message’: ‘explanation of error’}</code></pre>
				</li>
			</ul>
		</li>
	</ul>
</ul>
For a working example, view our [Magento plugin
version](https://github.com/amzn/amazon-payments-magento-plugin/blob/master/app/code/community/Amazon/Payments/Model/SimplePath.php)
of this code, available in Github.