Git Product home page Git Product logo

solidus_afterpay's People

Contributors

christianrimondi avatar garciajordy avatar mtylty avatar vassalloandrea avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

solidus_afterpay's Issues

Implement the Afterpay Express Checkout

Documentation here


Currently Afterpay supports:

  • Integrated Shipping:​ Delivery options are displayed to users in real time, with the ability to confirm the order within Afterpay.

  • Deferred Shipping:​ The user returns to the retailer site to finalize delivery options and complete the order.

Integrated Shipping Deferred Shipping
Less than 5 shipping options More than 5 shipping options
Simple shipping options (i.e. single optionfor whole order) Complex shipping options (e.g. individual options at SKU level)
Simple tiered shipping options (e.g. standard, express, rush) Time Slot Booking
Pickup in-store option before checkout entry Mixed in-store pickup and home delivery

and I think we should start with the integrated shipping first.

Integrated Shipping

This feature improves the user experience by embedding your shipping options directly into the Afterpay Express Checkout flow. It streamlines the checkout process and can be combined with the buyNow flag to create a one-stop checkout that immediately precedes the order confirmation page.

Integrated Shipping is configured in the call to initializeForPopup triggered by the Express Checkout button.

It requires shippingOptionRequired to be true (enabled by default) and an onShippingAddressChange callback must be defined:

AfterPay.initializeForPopup({
  countryCode: 'US',
  onCommenceCheckout: function(actions) {
    /* retrieve afterpay token from your server */
    /* then call `actions.resolve(token)` */
  },
  onShippingAddressChange: function (data, actions) {
    /* required for Integrated Shipping  */
    /* address in `data` */
    /* calc options, then call `actions.resolve(options)` */
  },
  onShippingOptionChange: function (data) {
    /* optional - chosen option in `data` */
  },
  onComplete: function (data) {
    /* handle success/failure of checkout */
  },
  target: '#afterpay-express-button',
  buyNow: false,
  pickup: false,
  shippingOptionRequired: true
})

Listening for Address Changes

The Shipping Address Change callback is a feature of the Express Checkout. This callback allows a merchant to dynamically update shipping options and taxes based on the shipping address chosen by the consumer.

The shipping address change callback is required:

  • If you intend to update the order total based on a chosen shipping address.
  • To validate that you can ship to the selected address.

To set up the Shipping Address Change callback, implement the onShippingAddressChange function. This function will be passed two arguments: data and actions.

How the shipping options are calculated is entirely managed by the merchant. They can be calculated in Javascript or by handing off to an internal API.

If shipping options are available for the given address, they can be returned to Afterpay using the resolve action as shown in the code example below. Similarly, the reject action is used when shipping is unavailable.

AfterPay.initializeForPopup({
  // ...
  onShippingAddressChange: function (data, actions) {
    fetch('/your-shipping-endpoint', {
      method: 'POST',
      headers: { 'content-Type': 'application/json' },
      body: JSON.stringify(data),
    }).then(function(options) {
      actions.resolve(options)
    }).catch(function(error) {
      // Parse the response and send an AfterPay rejection, e.g.:
      actions.reject(AfterPay.CONSTANTS.SHIPPING_UNSUPPORTED)
    })
  },
})

Afterpay calls your onShippingAddressChange function when:

  • The consumer first enters the Afterpay summary page
  • The consumer makes a change to their shipping address on the Afterpay summary page

Afterpay provides the following parameters to your onShippingAddressChange function:

data parameter: This contains the consumer’s selected address with fields:

  • suburb, state, postcode, and countryCode

action parameter: This object is used to return your response to the Afterpay checkout. It consists of the following methods:

  • resolve : Call this method to provide the shipping options applicable to the consumers address. Takes an array of Shipping Option objects.

  • reject : Call this method when you are unable to handle the request. Do not throw an error, instead call this method with a Shipping Constant as the first argument to indicate a status, e.g.:

actions.reject(AfterPay.CONSTANTS.SHIPPING_UNSUPPORTED)

Shipping Option model

Attribute Type Description
id String (required) A shipping option identifier. Max length 128
name String (required) The name of the shipping options
shippingAmount Money (required) The shipping amount (without tax, if including taxAmount)
taxAmount Money (optional) The tax amount
orderAmount Money (required) The total amount for the order including shipping and taxes
description String A description for this shipping option

Deferred payment flow bug

From the documentation: https://developers.afterpay.com/afterpay-online/docs/api-calls-and-payment-flows I'm expecting that the correct behavior is:

  • With the deferred flow, when a user makes an order, the payment is not captured and the installments plan is not started until the admin user goes to the order payments and makes the payment as captured. (auto-capture off)
  • With the immediate flow, when a user makes an order, the payment is captured and the installments plan is started. (auto-capture on)

Actual behavior:

  • With the auto-capture enabled, the payment is captured using the immediate flow and the installment plan is starting (correct)
  • With the auto-capture disabled, the payment is not captured - Solidus side - but is captured Afterpay side with the deferred payment flow starting the installments flow and charging the user with the first installment (WRONG)

I think that the problem is related to this line: https://github.com/nebulab/solidus_afterpay/blob/65346f79f49e2d119a747718e63f1395b170a9dd/app/models/solidus_afterpay/gateway.rb#L68

What do you think? @mtylty @ChristianRimondi @garciajordy

Bug on callbackscontroller for redirecting when finishing the checkout

https://github.com/nebulab/solidus_afterpay/blob/2a34867f92cbd3be6e28e6c85bd5204e295391a3/app/controllers/solidus_afterpay/callbacks_controller.rb#L17

Here we are using the solidus_frontend endpoint to retrieve the URL of the current state of the order, but if the client is only using the solidus_backend and have their own frontend, this will throw an error.

A solution would be to add a preference on the payment method for retrieving a custom endpoint.

Fix the success method for Afterpay javascript

image
On the latest version of Solidus you should pass the success and error functions as parameters.

A solution would be:
from

Spree.ajax({
          method: "POST",
          url: "/solidus_afterpay/checkouts.json",
          data: {
            order_number: orderNumber,
            payment_method_id: paymentMethodId,
          },
        })
          .success(function (response) {
            onSuccess(response);
          })
          .error(function (response) {
            onError(response);
          });

to

   Spree.ajax({
          method: "POST",
          url: "/solidus_afterpay/checkouts.json",
          data: {
            order_number: orderNumber,
            payment_method_id: paymentMethodId,
          },
          success: function (response) {
            onSuccess(response);
          },
          error: function (response) {
            onError(response);
          }
        });

The only question left is: Would this also work for older versions of solidus?

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.