### How do I initiate Affirm checkout in a modal instead of redirect checkout flow?
When you send a Sessions service request, you receive `
merchantURL` as one of the fields in a successful Sessions reply. If you'd like to render Affirm checkout in a modal instead of redirecting the user to the Affirm checkout, you would need to retrieve the `
preapprovalToken` prior to initiating a redirect to the "merchantURL". You can then use the `
checkout_token` to initiate the checkout in a Affirm modal using `
Affirm.js`. You should also add additional callback functions to redirect to the same `
success_url` and `
cancel_url` value that was sent in the Sessions service. The `
onSuccess()` callback should also initiate the authorization request using the `
checkout_token` before confirming the order on your site.
Sample PHP code can be found below, where you can retrieve the `
public_api_key` from the Merchant Portal and the version of `
Affirm.js` used should correspond to whether you're publishing your changes to a sandbox or production environment: