Skip to content

About

Repository containing the Magento 2 GraphQL plugin by Buckaroo

Resources

Contributing

Stars

1 star

Watchers

11 watching

Forks

 
 

Latest commit

 

History

55 Commits

Folders and files

Repository files navigation

Buckaroo — GraphQL for Magento 2

Buckaroo GraphQL module for Magento 2

About · Requirements · Installation · Upgrade · Usage · Support · Contribute


About

GraphQL is a query language for APIs. It describes the data your API exposes, lets a client ask for exactly what it needs and nothing more, and makes it easier to evolve the API over time.

This module exposes Buckaroo's payment methods through Magento's GraphQL API, so a headless or single-page storefront can list the available methods, set one on the cart, place the order and check the payment status.

Important

The Buckaroo Magento 2 plugin is required. This module extends it and cannot be used on its own — install and configure the payments plugin first.

It is also a prerequisite for the Hyvä React Checkout module, which relies on these GraphQL endpoints.

Full module documentation on docs.buckaroo.io


Requirements

Requirement Supported versions
Buckaroo Magento 2 plugin 2.7 or higher (use module 1.1.x with plugin 1.x)

Magento, PHP and Composer requirements come from the main plugin. You also need a Buckaroo account — don't have one yet? Request an account.


Installation

Run the following commands from your Magento 2 root folder:

composer require buckaroo/magento2graphql
php bin/magento module:enable Buckaroo_Magento2Graphql
php bin/magento setup:upgrade
php bin/magento cache:flush

Upgrade

composer update buckaroo/magento2graphql
php bin/magento setup:upgrade
php bin/magento cache:flush

Tip

Always test an upgrade on a staging environment first.


Usage

Payment methods are enabled and configured in the main plugin, under Stores → Configuration → Sales → Buckaroo in the Magento admin. This module only exposes them; it has no settings of its own.

Listing the available payment methods

Each method comes back with its Buckaroo-specific extra data under buckaroo_additional:

query {
    cart(cart_id: "{ CART_ID }") {
        available_payment_methods {
            code
            title
            buckaroo_additional {
                key
                values {
                    name
                    code
                    img
                }
                value
            }
        }
    }
}

Placing an order

Placing an order takes three steps, which can be combined into one mutation:

  1. Set the payment method on the cart with the standard setPaymentMethodOnCart, passing any method-specific fields under buckaroo_additional.
  2. Set the return URL with setBuckarooReturnUrl, so the payment engine knows where to send the customer after the payment completes, is cancelled or fails.
  3. Call the standard placeOrder, which returns the redirect URL.
mutation doBuckarooPayment(
  $cartId: String!
  $returnUrl: String!
  $methodCode: String!
) {
  setPaymentMethodOnCart(
    input: {
      cart_id: $cartId
      payment_method: {
        code: $methodCode
        buckaroo_additional: { buckaroo_magento2_ideal: {} }
      }
    }
  ) {
    cart {
      items {
        product {
          name
          sku
        }
      }
    }
  }
  setBuckarooReturnUrl(input: { return_url: $returnUrl, cart_id: $cartId }) {
    success
  }
  placeOrder(input: { cart_id: $cartId }) {
    order {
      order_number
      buckaroo_additional {
        redirect
        transaction_id
        data {
          key
          value
        }
      }
    }
  }
}

Store the returned transaction_id, then redirect the customer to the redirect URL to complete the payment.

Note

iDEAL no longer requires an issuer, so buckaroo_magento2_ideal can be left empty. The customer picks their bank on the redirect page.

SEPA Direct Debit example

SEPA Direct Debit needs the mandate details passed as additional fields:

mutation doSepaPayment($cartId: String!, $returnUrl: String!) {
  setPaymentMethodOnCart(
    input: {
      cart_id: $cartId
      payment_method: {
        code: "buckaroo_magento2_sepadirectdebit"
        buckaroo_additional: {
          buckaroo_magento2_sepadirectdebit: {
            customer_iban: "NL13TEST0123456789"
            customer_bic: "TESTNL2A"
            customer_account_name: "Test Account Holder"
          }
        }
      }
    }
  ) {
    cart {
      selected_payment_method {
        code
      }
    }
  }
  setBuckarooReturnUrl(input: { return_url: $returnUrl, cart_id: $cartId }) {
    success
  }
  placeOrder(input: { cart_id: $cartId }) {
    order {
      order_number
      buckaroo_additional {
        transaction_id
      }
    }
  }
}

Retrieving the payment status

Once the customer is redirected back, query the status with the stored transaction_id:

mutation {
  buckarooPaymentTransactionStatus(input: { transaction_id: "E397CF4C24E64AA299F45246F9906F45" }) {
    payment_status
    status_code
  }
}

For dynamic values, use variables instead:

mutation checkPaymentStatus($input: BuckarooPaymentTransactionStatusInput!) {
  buckarooPaymentTransactionStatus(input: $input) {
    payment_status
    status_code
  }
}
{
  "input": {
    "transaction_id": "E397CF4C24E64AA299F45246F9906F45"
  }
}

Support

Having trouble? Work through this list before reaching out:

  1. Confirm the main plugin is installed and active, and that the method works in a standard Magento checkout.
  2. Confirm you are on the latest release of both this module and the main plugin.
  3. Check that the method code and the buckaroo_additional key match, for example buckaroo_magento2_ideal for code buckaroo_magento2_ideal.
  4. Flush the cache after installing or upgrading.

Still stuck? Contact us and include your Magento version, main plugin version, this module's version, the query or mutation you sent and the response you received.


Contribute

We really appreciate it when developers help improve the Buckaroo plugins. Please read our Contribution Guidelines before opening a pull request, and target the main branch.

Found a security issue? Please report it privately to support@buckaroo.nl instead of opening a public issue.


Versioning

We follow semantic versioning (MAJOR.MINOR.PATCH):

  • MAJOR — breaking changes that require additional testing and caution.
  • MINOR — new functionality with limited impact.
  • PATCH — bug fixes and hotfixes only.

License

This module is open source software licensed under the MIT license.


Made with care by Buckaroo.
This document is subject to change; typos and language errors are possible.

About

Repository containing the Magento 2 GraphQL plugin by Buckaroo

Resources

Contributing

Stars

1 star

Watchers

11 watching

Forks

Releases

Packages

Used by

Contributors

Languages