<script>
  import { createEventDispatcher } from 'svelte';
  import api from "$/client/api.js";

  const dispatch = createEventDispatcher();

  const dispatch_finished = async (ev) => {
    const [status, data] = await api.post("/api/payments/fake");
    if(status == 200) {
      dispatch("finished", ev);
    } else {
      console.log("Failed to post to fake", data);
      dispatch("error", ev);
    }
  }
</script>

<button data-testid="fake-payment-button" type="button" on:click={ (ev) => dispatch_finished(ev) }>
  Fake Payment
</button>

<button data-testid="fake-payment-cancel" type="button" on:click={ (ev) => dispatch("canceled", ev) }>
  Cancel
</button>


<button data-testid="fake-payment-error" type="button" on:click={ (ev) => dispatch("error", ev) }>
  Cause Error
</button>
