Capturing the Payment Token

To capture and store payment method tokens created by PayNearMe to use for future payments, you can choose between a simple page refresh, or you can create your own callback function.

Using the Simple Refresh Method

For the simple refresh method, the Embedded Form uses a <script> tag to render the payment process. After the agent enters the applicable payment method details and exits the Embedded Form modal, the page automatically refreshes. At the time of payment, the agent uses the [/find_order](https://paynearme-enterprise-group.readme.io/paynearme-devdocs/reference/post_find-orders) API call to retrieve the payment method token that is now associated with that order. The following example displays the code for a simple refresh. This example also adds a prompt to the Embedded Form modal, prefills the customer’s details, and limits the allowable payment methods to just debit cards.

<button id=push_it>Add New Payment Method</button>
<script
src="https://www.paynearmeeng.com/api/embedded/hr_59T5GRs0mb_gufojPvg/scrip t.js?prompt=Add a payment method for the customer&name=John Smith&address=123 Fake Street&zip=75013&only=debit" data-button=push_it></script>

Using the Callback Function Method

Use the callback function method to “stuff” the newly created token into your payment form when the agent initiates the transaction. The following code sample takes the payment method token and adds it to the hidden field new_card. Once the agent submits the payment form to your server, you can use the token in a [/make_payment](https://paynearme-enterprise-group.readme.io/paynearme-devdocs/reference/post_make-payment) API call.

<form action='URL on your server'>
  <input type=hidden id=new_card >
  <input type=submit value='Make A Payment'>
</form>

<button id=push_it>Add New Payment</button>
<script
src="https://www.paynearmeeng.com/api/embedded/4Gi890UCCwzBpTXC3jpmpw/script.js?" data-button=push_it data-callback=echo></script>

<script>
  function echo(result){document.getElementById('new_card').value=result.token;}
</script>

What’s Next