 window.giftCardsProviders = ko.observableArray()
 setup = (location, route) ->
   window.paymentData = new PaymentDataViewModel({route: route, location: location});
+  window.allowedOrigin = location.protocol + '//' + location.host
   ko.components.register('payment-data', {
     viewModel: {instance: window.paymentData},
     template: paymentDataTemplate

Listens to events by the parent window
###
$(window).on "message onmessage", (e) ->
  console.log 'Payment data received message', e.originalEvent?.data
  event = e.originalEvent.data.event
  args = e.originalEvent.data.arguments

###
Converts events sent by the component to messages to the parent window.
###
$(window).on "sendAttachment.vtex", (e, attachmentName, attachmentData) ->
  parent.postMessage({"event": "sendAttachment.vtex", "arguments": [attachmentName, attachmentData]}, window.allowedOrigin)

$(window).on "componentValidated.vtex", (e, validationResults) ->
  parent.postMessage({"event": "componentValidated.vtex", "arguments": [validationResults]}, window.allowedOrigin)

$(window).on "startTransaction.vtex", (e, value, referenceValue, payments) ->
  parent.postMessage({"event": "startTransaction.vtex", "arguments": [value, referenceValue, payments]}, window.allowedOrigin)

$(window).on "removeAccount.vtex", (e, accountId) ->
  parent.postMessage({"event": "removeAccount.vtex", "arguments": [accountId]}, window.allowedOrigin)

$(window).on "authenticateUser.vtexid", (e, options) ->
  parent.postMessage({"event": "authenticateUser.vtexid", "arguments": [options]}, window.allowedOrigin)
