solidusio-contrib / solidus_afterpay Goto Github PK
View Code? Open in Web Editor NEWLicense: Apache License 2.0
License: Apache License 2.0
Updating the SolidusAftepay::PaymentMethod
sets the minimum_amount
and maximum_amount
preferences to 0.0
instead of leaving them nil
. This is causing an issue here because instead of retrieving the configuration from Afterpay, the method always returns a 0.0..0.0
range.
Using the auto_capture
method doesn't fallback to the global default if it's nil
https://github.com/solidusio/solidus/blob/master/core/app/models/spree/payment_method.rb#L145-L147
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.
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
})
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:
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:
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)
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 |
From the documentation: https://developers.afterpay.com/afterpay-online/docs/api-calls-and-payment-flows I'm expecting that the correct behavior is:
Actual behavior:
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
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.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.