Giter Site home page Giter Site logo

commerce-afterpay's Introduction

Afterpay for Craft Commerce icon

Afterpay plugin for Craft Commerce

This plugin provides an Afterpay gateway for Craft Commerce (2 & 3).

Features

  • AU, NZ and US Regions (AU tested, NZ and US Pending SAT)
  • Full and Partial refund support
  • Authorisation and Total mismatch detection (passes Afterpay SAT)
  • User-Agent headers (passes Afterpay SAT)
  • Excellent Afterpay API response debugging
  • Native Commerce 2 Integration (no OmniPay abstraction)

Screenshots

Settings Transactions Transaction details

Requirements

This plugin requires Craft CMS 3.1 or later and Craft Commerce 2.x or Craft Commerce 3.x.

Installation

Plugin Store

Direct link to plugin store

To install Afterpay for Craft Commerce, navigate to the Plugin Store section of your Craft control panel, search for Afterpay for Craft Commerce, and click the Try button.

Composer

You can also add the package to your project using Composer.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require newism/commerce-afterpay
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Afterpay.

Configuring Afterpay

First you'll need to setup a merchant account. This can be done by emailing Afterpay.

Once you have a merchant account you'll be provided with a Merchant ID and Merchant Key.

To add the Afterpay payment gateway, go to Commerce → Settings → Gateways, create a new gateway, and set the gateway type to “Afterpay”.

You may then decide to configure your Afterpay gateway using a config file. An example file looks like:

<?php
return [
    'afterpayGatewayHandle' => [
        'sandboxMode' => getenv('AFTERPAY_SANDBOX_MODE'),
        'merchantId' => getenv('AFTERPAY_MERCHANT_ID'),
        'merchantKey' => getenv('AFTERPAY_MERCHANT_KEY'),
        // Must be 'AU', 'NZ' or 'US'
        'region' => getenv('AFTERPAY_REGION'),
    ],
]; 

Currency Support

Afterpay only supports one currency per region. Due to this limitation stores must set their base currency to match their Afterpay account region. Payments will be processed in the base currency.

Region Currency Docs
AU AUD https://docs.afterpay.com/au-online-api-v1.html#money-object
NZ NZD https://docs.afterpay.com/nz-online-api-v1.html#money-object
US USD https://docs.afterpay.com/us-online-api-v1.html#money-object

Support

GitHub

If you've found a bug, or would like to make a feature request, head to the GitHub Repo and file an issue. Pull requests are also most welcome!

Twitter

Get our attention on Twitter by using the #craftcms hashtag and mentioning @newism

Stack Exchange

Ask a question via the Craft Stack Exchange and tag your question with plugin-newism-commerce-afterpay.

Email

Any feedback, comments, questions or suggestions please email us at support at newism.com.au.

Licensing

You can try this plugin in a development environment for as long as you like.

For more information, see Craft's Commercial Plugin Licensing.


Afterpay for Craft Commerce icon

Brought to you by Newism

commerce-afterpay's People

Contributors

dwhoban avatar engram-design avatar janhenckens avatar leevigraham avatar

Stargazers

 avatar

Watchers

 avatar  avatar

commerce-afterpay's Issues

redirect template points to sandbox version of afterpay.js

src/templates/redirect.html.twig contains a the line:

<script src="https://portal.sandbox.afterpay.com/afterpay.js" async></script>

This does not work with production; and requires a variable to be created to honor the sandbox setting.

Craft 4?

Hi,

Will there be a Craft 4 version soon?

Thanks

[FR] Make the Merchant Reference a setting

Currently the plugin uses the Transaction Hash as the Merchant Reference for Afterpay.

Afterpay now require it to match what is being used for the customer order in Craft. The default reference for Craft seems to be order->shortNumber but anything could be used in the template.

This could be a setting in the Gateway Config

Deprecated method calls

In AfterpayGateway.php
Order::getAdjustmentsTotalByType()has been deprecated. UseOrder::getTotalTax(), Order::getTotalDiscount(), or Order::getTotalShippingCost()` instead.

Afterpay > Clearpay

We have an AUS client that wants to use this gateway on their site, but also wants to integrate it with EUR also.

I originally didn't think it existed for EUR, but after doing some research Afterpay does exist, but in EUR it is called Clearpay (Some legal rubbish) - So will this work for both, as it's the same company?

Or would I be looking at a different plugin?

https://docs.afterpay.com/uk-online-api-v1.html

Discounts array not returning values.

Craft 3.2 changed the way discounts worked to be line items. As part of this getOrderAdjustmentsByType($order, 'discount') appears to no longer work. Have temporarily replaced with a hacky workaround but needs a more elegant solution:

            'discounts' =>  array(
                [
                    'displayName' => 'Total Discount',
                    'amount' => [
                        'amount' => abs(Currency::round($order->totalDiscount)),
                        'currency' => $order->currency,
                    ],
                ],
            ),

EU region support

I see in the code that the EU region should be supported, however it's not mentioned in the documentation.

So.. Is it supported?:)

Invalid/Improperly formatted JSON in submission in Commerce 3.0

When checking out with Afterpay on Commerce 3 payment always fails due to errorCode: "invalid_json" regardless of product details.

Error response is also truncated so there is limited information.

 Client error: `POST https://api-sandbox.afterpay.com/v1/orders` resulted in a `400 Bad Request` response: { "errorCode" : "invalid_json", "errorId" : "03dcc4e24f5a671c", "message" : "The request contains improperly forma (truncated...) 

Can't install

Not sure why but I can't install this plugin either through the plugin store or composer. I get the error:

  [InvalidArgumentException]                                                                                                                                                                                               
  Could not find a matching version of package newism/commerce-afterpay. Check the package spelling, your version constraint and that the package is available in a stability which matches your minimum-stability (stabl  
  e). 

I checked Packagist and it does look like the package doesn't exist. Is this a mistake?

I finally got round to convincing the client to use this plugin and it won't install! 😂

User Agent Header needs to be configurable

Our Afterpay integration is getting rejected due to this issue:

User Agent Header requests are used to assist Customer Service and Support Teams when troubleshooting integration and consumer issues

API Documentation: https://docs.afterpay.com/merchant-api-v1.html#request-headersUser Agent Header is required as part of Afterpay business policy

All Merchants are required to supply User Agent Header with each type of API request 

User Agent Header Syntax
Syntax: <pluginOrModuleOrClientLibrary>/<pluginVersion> (<platform>/<platformVersion>; Merchant/<merchantId>) <environment URL>

The problem in our case is this is a multi-site, where each site is a subdirectory.

https://site.dev/australia-nz
https://site.dev/uk
https://site.dev/usa

The User agent is hard-coding this to https://site.dev/about which they're flagging as incorrect. It should be https://site.dev/australia-nz. We need a way to modify this URL, ideally an environment variable, alias or gateway setting.

Missing brackets in Settings.twig

Version 2.2. has some brackets missing in vendor/newism/commerce-afterpay/src/templates/gateway/settings.twig.html

chrome_2020-11-24_11-30-04

Solution: Add
}) }}
to line 42

image

passing idempotent Afterpay requests?

Good day,

I'm implementing your Afterpay plugin on a Craft 3 eCommerce site.
Afterpay have sent the following requirement with regards to processing refunds:

Requirements

The Afterpay API supports idempotent requests, allowing for safe retry of requests (e.g. refund attempts) without risking accidentally processing a request twice
To support refund idempotency, refund calls must be issued with both a merchantReference and requestId attribute

Test Analyst Results

Client name here are currently passing ‘null’ values for both merchantReference and requestID

Merchant Services advise developer efforts to ensure both merchantReference and requestId attributes are passed along with all refund API calls.

Is this a setting that I've missed or something else?

Orders being marked as paid before completing Afterpay transaction.

I'm having an issue where orders are immediately being marked as paid when the user is redirected to the Afterpay checkout.

I basically redirect the user to checkout by submitting a form with:

        <input type="hidden" name="action" value="commerce/payments/pay">
        {% nocache %}
          {{ csrfInput() }}
        {% endnocache %}
        {{ redirectInput('/checkout/order?number='~cart.number) }}
        <input type="hidden" name="cancelUrl" value="{{ '/checkout/payment'|hash }}"/>

Also if I click cancel on the Afterpay checkout my cancelUrl is not respected and I am redirected to SITE_URL

Here is the transaction information for the order, even though I didn't complete a transaction.

Screen Shot 2020-03-24 at 4 50 09 pm

paymentCurrency vs. currency

We're getting an error on a multi-site, multi-currency install:

Client error: `POST https://api-sandbox.afterpay.com/v1/orders` resulted in a `422 Unprocessable Entity` response:
{
"errorCode" : "unsupported_currency",
"errorId" : "c613326b60e14219",
"message" : "An error occurred",
"httpSt (truncated...)

We're following https://craftcms.com/docs/commerce/3.x/payment-currencies.html#switching-currencies by setting the paymentCurrency for an order, for a particular site. Commerce's currency handling seems a bit odd, where you can't set the order->currency. See craftcms/commerce#790

The primary site's currency is in GBP, but we're on the AU site, trying to pay in AUD (paymentCurrency is set to AUD). I believe you just can't change the currency attribute on an order, and it'll be whatever your primary currency is. So the error is valid, GBP isn't supported.

Any reason for using the currency over the order's paymentCurrency? Changing this works.

JS Error on redirect

I'm getting the following error on the step before redirect.

image

This seems like a valid error, but I've got this plugin on a few sites now with no issue. I'm not sure what the deal is there, because I can't see how this wouldn't be an issue! It's plain invalid JS, as it's missing a }.

AfterPay.initialize({countryCode: {{ region }});

vs

AfterPay.initialize({countryCode: "{{ region }}"});

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.