@frontend_royalties
@lambda_documents
@documents
@ows_payment
@ows-payee
@graphql_tax_payment
@lambda_documents_payee
Feature: Abacus custom payment

  Background:
    Given an orchard employee label_7123_admin_5 for abacus
    When I log in

  @id_c1e02c367740803a1b431593cf14edea000c96c97361f0537e335dbfdc70148
  Scenario: Create/approve a custom payment
    Given I prepare an abacus account data:
      | Key              | Value                   |
      | companyBrandName | awal                    |
      | paidBy           | AWAL-UK                 |
      | agreementType    | AWAL Core               |
      | currency         | GBP                     |
      | owner            | awal                    |
      | paymentMinimum   | 100                     |
      | paymentSchedule  | 45 days after month end |
    And I create 1 new active accounts via API
    And I have a Distribution runcontroller created
    And I have a new Distribution contract lifecycle created with accounts created for AWAL Recordings Licensing Ltd
    And I update account_payee and account_tax_info tables
    # This program in payoneer 100246490 has disabled rules to trigger webhook for testing purposes, so we trigger webhooks with tests
    And I update payoneer id in DB to 100246490
    When I should be able to add a custom payment for specific account
    And I should be redirected to custom generated Payment
    Then I export created payment
    And I should be able to review and approve the Custom payment
    Then I send payment to Payoneer
    When I should be able to open account details
    Then I check that Account Activity has event Custom Payment
    Then I check that Account Activity has event VAT
    Then I check that Account Activity has event Tax Withholding
    Then I trigger webhook to make Custom payment approved from payoneer
    Then I trigger webhook to make Custom payment completed from payoneer
    Then I should see that payment status is Paid
    Then I should NOT be able to delete custom payment
    Then I click on Clear all checkboxes for custom payment view
    Then I can enable some specific checkboxes for custom payment view
    Then I click on Select all checkboxes for custom payment view
    Then I should be able to see payment in Custom Payment section
    And I check ledger_vat_summary has the following values:
      | column                    | value         |
      | wht_rate                  | null          |
      | wht_amount_vat_currency   | null          |
      | wht_amount_payee_currency | null          |
      | vat_rate                  | ctx.vatRate   |
      | vat_amount_vat_currency   | ctx.vatAmount |
      | vat_amount_payee_currency | ctx.vatAmount |
    Then I trigger webhook to make Custom payment canceled from payoneer
    When I should be able to open account details
    Then I check that Account Activity has event Custom Payment Returned
    Then I check that Account Activity has event VAT Returned
    Then I check that Account Activity has event Tax Withholding Returned

  @id_2009f83b98e7a3840a384823cec697fb5703fea2a3069c0cfc822d2a9ad49e35
  Scenario: Create a custom payment for ORCHARD-ES account that is on hold
    Given I prepare an abacus account data:
      | Key              | Value                   |
      | companyBrandName | awal                    |
      | paidBy           | ORCHARD-ES              |
      | agreementType    | Orchard                 |
      | currency         | EUR                     |
      | paymentMethod    | payoneer_whitelabel     |
      | owner            | orchard                 |
      | paymentMinimum   | 100                     |
      | paymentSchedule  | 45 days after month end |
    And I create 1 new active accounts via API
    And I have a Distribution runcontroller created
    And I have a new Distribution contract lifecycle created with accounts created for Altafonte Network, S.L.U
    And I update account_payee and account_tax_info tables
    # This program in payoneer 100246490 has disabled rules to trigger webhook for testing purposes, so we trigger webhooks with tests
    And I update payoneer id in DB to 100246490
    And I should be able to put account's Payment Eligibility on hold
    When I should be able to add a custom payment for specific account
    And I should be redirected to custom generated Payment
    And I should be able to review and approve the Custom payment
    Then I send payment to Payoneer
    When I should be able to open account details
    Then I check that Account Activity has event Custom Payment
    Then I check that Account Activity has event VAT
    Then I check that Account Activity has event Tax Withholding
    Then I trigger webhook to make Custom payment canceled from payoneer
    Then I should see that payment status is Cancelled
    Then I should be able to see payment in Custom Payment section
    And I check ledger_vat_summary has the following values:
      | column                    | value         |
      | wht_rate                  | ctx.whtRate   |
      | wht_amount_vat_currency   | ctx.whtAmount |
      | wht_amount_payee_currency | ctx.whtAmount |
      | vat_rate                  | ctx.vatRate   |
      | vat_amount_vat_currency   | ctx.vatAmount |
      | vat_amount_payee_currency | ctx.vatAmount |
    When I should be able to open account details
    Then I check that Account Activity has event Custom Payment Returned
    Then I check that Account Activity has event VAT Returned
    Then I check that Account Activity has event Tax Withholding Returned
