Solidus Returnly
This gem adds the required APIs to allow Returnly to obtain an estimate, process a return, and apply a reimbursement
Spree/Solidus
This gem can be installed on spree and solidus, to release a new version to both registries you need to run
bash
$ rake both_releases
this will generate two packages, solidus-returnly
and spree-returnly
Current Compat Versions:
- Solidus :
~> 2.4.0
- Spree :
~> 3.1.0
Installation
Add solidus_returnly to your Gemfile:
gem 'solidus-returnly'
Bundle your dependencies and run the installation generator:
bundle
bundle exec rails g solidus_returnly:install
Testing
First bundle your dependencies, then run rake
. rake
will default to building the dummy app if it does not exist, then it will run specs, and Rubocop static code analysis. The dummy app can be regenerated by using rake test_app
.
bundle
bundle exec rake
When testing your applications integration with this extension you may use it's factories. Simply add this require statement to your spec_helper:
require 'solidus/returnly/factories'
Solidus/Spree Sandbox
You can create a sandbox spree installationm
git clone [email protected]:solidusio/solidus.git
cd solidus
git co v2.0
bundle install
rake sandbox
cd sandbox
rake spree_auth:admin:create
default admin credentials:
Email [[email protected]]
Password [test123]
this will create a pristine solidus installation you can add the solidus_returnly
gem and test the endpoints live
API
To get an estimate of the return order and taxes
POST /api/returnly/orders/:order_number/refund_estimate
Payload:
{
"items": [
{
"order_line_item_id": "{spree order line item id}",
"units": 1
}
]
}
Response:
{
"product_amount": "{money}",
"tax_amount": "{money}",
"discount_amount": "{money}",
"total_refund_amount": "{money}",
"refundable_shipping_amount": "{money}",
"refundable_shipping_tax_amount": "{money}",
"max_refundable_amount": "{money}",
"transactions": [
{
"id": "{refund tx id}",
"amount": "{money}",
"status": "PENDING",
"type": "REFUND",
"gateway": "{gateway}",
"is_online": true,
"is_test": true,
"payment_details": {
"avs_result_code": "{code}",
"cvv_result_code": "{code}",
"credit_card_number": "{number}",
"credit_card_company": "visa",
"gift_card_id": "{voucher_id}",
"gift_card_code": "{voucher_code}"
},
"created_at": "{date}"
}
]
}
To process the return and apply the reimbursement*immediately*
you can pass the restock
parameter on false to prevent the api
to immediately change the stock in the default warehouse
POST /api/returnly/orders/:order_number/refund
Payload:
{
"items": [
{
"order_line_item_id": "{x_order_line_item_id1}",
"units": 2,
"restock": true
}
],
"notify_shopper": true,
"product_refund_amount": "{money}",
"shipping_refund_amount": "{money}",
"refund_note": "comment text"
}
Response:
{
"refund_id": "{x_refund_id}",
"user_id": "{optional merchant user ID}",
"line_items": [
{
"refund_line_item_id": "{x_refund_line_item_id1}",
"order_line_item_id": "{x_order_line_item_id1}",
"units": 2
},
],
"transactions": [
{
"id": "{refund tx id}",
"amount": "{money}",
"status": "PENDING",
"type": "REFUND",
"gateway": "{gateway}",
"is_online": true,
"is_test": true,
"payment_details": {
"avs_result_code": "{code}",
"cvv_result_code": "{code}",
"credit_card_number": "{number}",
"credit_card_company": "visa",
"gift_card_id": "{voucher_id}",
"gift_card_code": "{voucher_code}"
}
}
],
"created_at": "{date}",
"updated_at": "{date}",
"refund_note": "comment text",
}
Overriding Refund Logic
Is possible to override the default behavior of the Refund Gem by extending the following classes
lib/returnly/refund/return_item_restock_policy.rb
class CustomReturnItemRestockPolicy < ReturnItemRestockPolicy
def should_return_item?(return_item)
return_item.cost > 1
end
end
lib/returnly/refund/amount_calculator.rb
class CustomAmountCalculator < AmountCalculator
def return_item_refund_amount(return_item)
default_amount(return_item) - 5.0
end
end
to set your custom classes to the returns process just
add an initializer file: cofnig/initializers/returnly.rb
Returnly.configure do |config|
config.return_item_amount_calculator = CustomAmountCalculator
config.return_item_restock_policy = CustomReturnItemRestockPolicy
config.refunder = CustomRefunder
config.refund_calculator = CustomRefunderCalculator
config.reimbursement_type_no_items = CustomOriginalPaymentNoItems
config.refund_presenter = CustomRefundPresenter
config.return_item_builder = CustomReturnItemBuilder
end
Copyright (c) 2017 Returnly Technologies, Inc