Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Removes the Store API Create Payment endpoint + fixed Stock Location serializer
Damian Legawiec536e6014fa3d
diff --git a/api/app/controllers/spree/api/v3/store/orders/payments_controller.rb b/api/app/controllers/spree/api/v3/store/orders/payments_controller.rbindex a20e5760af..bfb67c8aab 100644--- a/api/app/controllers/spree/api/v3/store/orders/payments_controller.rb+++ b/api/app/controllers/spree/api/v3/store/orders/payments_controller.rb@@ -24,40 +24,17 @@ module Spreerender json: serialize_resource(@payment)end- # POST /api/v3/store/orders/:order_id/payments- def create- result = create_payment_service.call(order: @order, params: payment_params)-- if result.success?- render json: serialize_order(@order.reload), status: :created- else- render_service_error(result.error)- end- end-- protected+ privatedef set_order@order = current_store.orders.friendly.find(params[:order_id])- authorize!(:update, @order, order_token)+ authorize!(:show, @order, order_token)enddef set_payment@payment = @order.payments.find_by!(prefix_id: params[:id])end- def payment_params- params.permit(- :payment_method_id,- :amount,- source_attributes: Spree::PermittedAttributes.source_attributes- )- end-- def create_payment_service- Spree::Api::Dependencies.storefront_payment_create_service.constantize- end-def serializer_classSpree.api.payment_serializerend@@ -65,10 +42,6 @@ module Spreedef serialize_payments(payments)payments.map { |p| serializer_class.new(p, params: serializer_params).to_h }end-- def serialize_order(order)- Spree.api.order_serializer.new(order, params: serializer_params).to_h- endendendenddiff --git a/api/app/serializers/spree/api/v3/stock_location_serializer.rb b/api/app/serializers/spree/api/v3/stock_location_serializer.rbindex fee69d18d9..f79922f165 100644--- a/api/app/serializers/spree/api/v3/stock_location_serializer.rb+++ b/api/app/serializers/spree/api/v3/stock_location_serializer.rb@@ -3,16 +3,12 @@ module Spreemodule V3class StockLocationSerializer < BaseSerializertypelize name: :string, address1: 'string | null', city: 'string | null',- zipcode: 'string | null', country_id: 'string | null',- country_iso: 'string | null', country_name: 'string | null',- state_id: 'string | null', state_text: 'string | null'+ zipcode: 'string | null', country_iso: 'string | null',+ country_name: 'string | null', state_abbr: 'string | null',+ state_text: 'string | null'- attribute :country_id do |stock_location|- stock_location.country&.prefix_id- end-- attribute :state_id do |stock_location|- stock_location.state&.prefix_id+ attribute :state_abbr do |stock_location|+ stock_location.state&.abbrendattributes :name, :address1, :city, :zipcode, :country_iso, :country_name, :state_textdiff --git a/api/config/routes.rb b/api/config/routes.rbindex c164679ccd..3ed5504811 100644--- a/api/config/routes.rb+++ b/api/config/routes.rb@@ -250,7 +250,7 @@ Spree::Core::Engine.add_routes doresource :store_credits, only: [:create, :destroy], controller: 'orders/store_credits'resources :line_items, only: [:create, :update, :destroy], controller: 'orders/line_items'resources :promotions, only: [:create, :destroy], controller: 'orders/promotions'- resources :payments, only: [:index, :show, :create], controller: 'orders/payments'+ resources :payments, only: [:index, :show], controller: 'orders/payments'resources :payment_methods, only: [:index], controller: 'orders/payment_methods'resources :shipments, only: [:index, :show, :update], controller: 'orders/shipments'enddiff --git a/api/spec/integration/spree/api/v3/store/payments_spec.rb b/api/spec/integration/spree/api/v3/store/payments_spec.rbindex cd528a64d8..2657f14f99 100644--- a/api/spec/integration/spree/api/v3/store/payments_spec.rb+++ b/api/spec/integration/spree/api/v3/store/payments_spec.rb@@ -5,143 +5,85 @@ require 'swagger_helper'RSpec.describe 'Payments API', type: :request, swagger_doc: 'api-reference/store.yaml' doinclude_context 'API v3 Store'- let(:user) { create(:user) }- let!(:order) { create(:order_with_line_items, store: store, user: user, state: 'payment') }- let!(:payment_method) { create(:credit_card_payment_method, stores: [store]) }- let!(:payment) { create(:payment, order: order, payment_method: payment_method) }+ let(:order) { create(:order_with_line_items, store: store, user: user, state: 'payment') }+ let(:order_id) { order.number }+ let(:payment_method) { create(:credit_card_payment_method, stores: [store]) }+ let!(:payment) { create(:payment, order: order, payment_method: payment_method, amount: order.total) }path '/api/v3/store/orders/{order_id}/payments' do- get 'List payments for an order' do+ parameter name: 'x-spree-api-key', in: :header, type: :string, required: true+ parameter name: 'Authorization', in: :header, type: :string, required: true+ parameter name: :order_id, in: :path, type: :string, description: 'Order number or ID'++ get 'List payments' dotags 'Payments'produces 'application/json'security [api_key: [], bearer_auth: []]- description 'Returns all payments associated with the order'-- parameter name: 'x-spree-api-key', in: :header, type: :string, required: true- parameter name: 'Authorization', in: :header, type: :string, required: false- parameter name: :order_id, in: :path, type: :string, required: true- parameter name: :order_token, in: :query, type: :string, required: false+ description 'Returns a list of payments for the specified order'response '200', 'payments found' dolet(:'x-spree-api-key') { api_key.token }let(:'Authorization') { "Bearer #{jwt_token}" }- let(:order_id) { order.number }schema type: :object,properties: {- data: { type: :array, items: { '$ref' => '#/components/schemas/StorePayment' } }- },- required: ['data']+ data: {+ type: :array,+ items: { '$ref' => '#/components/schemas/StorePayment' }+ },+ meta: { type: :object }+ }run_test! do |response|data = JSON.parse(response.body)- expect(data['data']).to be_an(Array)+ expect(data['data'].length).to eq(1)+ expect(data['data'].first['id']).to eq(payment.prefix_id)endendresponse '404', 'order not found' dolet(:'x-spree-api-key') { api_key.token }let(:'Authorization') { "Bearer #{jwt_token}" }- let(:order_id) { 'non-existent' }-- schema '$ref' => '#/components/schemas/ErrorResponse'-- run_test!- end- end-- post 'Create a payment' do- tags 'Payments'- consumes 'application/json'- produces 'application/json'- security [api_key: [], bearer_auth: []]- description 'Creates a new payment for the order using the specified payment method'-- parameter name: 'x-spree-api-key', in: :header, type: :string, required: true- parameter name: 'Authorization', in: :header, type: :string, required: false- parameter name: :order_id, in: :path, type: :string, required: true- parameter name: :order_token, in: :query, type: :string, required: false- parameter name: :body, in: :body, schema: {- type: :object,- properties: {- payment_method_id: { type: :string, description: 'Payment method ID' },- amount: { type: :number, description: 'Payment amount (optional, defaults to order total)' },- source_attributes: {- type: :object,- description: 'Payment source details (card info, etc.)',- properties: {- number: { type: :string },- month: { type: :string },- year: { type: :string },- verification_value: { type: :string },- name: { type: :string }- }- }- },- required: %w[payment_method_id]- }-- response '201', 'payment created' do- let(:check_payment_method) { create(:check_payment_method, stores: [store]) }- let(:'x-spree-api-key') { api_key.token }- let(:'Authorization') { "Bearer #{jwt_token}" }- let(:order_id) { order.number }- let(:body) do- {- payment_method_id: check_payment_method.id.to_s- }- end-- schema '$ref' => '#/components/schemas/StoreOrder'-- run_test!- end-- response '422', 'invalid payment method' do- let(:'x-spree-api-key') { api_key.token }- let(:'Authorization') { "Bearer #{jwt_token}" }- let(:order_id) { order.number }- let(:body) { { payment_method_id: 'invalid' } }+ let(:order_id) { 'invalid' }schema '$ref' => '#/components/schemas/ErrorResponse'-run_test!endendendpath '/api/v3/store/orders/{order_id}/payments/{id}' do- get 'Get a payment' do+ parameter name: 'x-spree-api-key', in: :header, type: :string, required: true+ parameter name: 'Authorization', in: :header, type: :string, required: true+ parameter name: :order_id, in: :path, type: :string, description: 'Order number or ID'+ parameter name: :id, in: :path, type: :string, description: 'Payment ID'++ get 'Get payment' dotags 'Payments'produces 'application/json'security [api_key: [], bearer_auth: []]- description 'Returns details of a specific payment'-- parameter name: 'x-spree-api-key', in: :header, type: :string, required: true- parameter name: 'Authorization', in: :header, type: :string, required: false- parameter name: :order_id, in: :path, type: :string, required: true- parameter name: :id, in: :path, type: :string, required: true, description: 'Payment ID'- parameter name: :order_token, in: :query, type: :string, required: false+ description 'Returns a single payment by ID'response '200', 'payment found' dolet(:'x-spree-api-key') { api_key.token }let(:'Authorization') { "Bearer #{jwt_token}" }- let(:order_id) { order.number }let(:id) { payment.prefix_id }schema '$ref' => '#/components/schemas/StorePayment'- run_test!+ run_test! do |response|+ data = JSON.parse(response.body)+ expect(data['id']).to eq(payment.prefix_id)+ expect(data['state']).to eq(payment.state)+ endendresponse '404', 'payment not found' dolet(:'x-spree-api-key') { api_key.token }let(:'Authorization') { "Bearer #{jwt_token}" }- let(:order_id) { order.number }- let(:id) { 'non-existent' }+ let(:id) { 'invalid' }schema '$ref' => '#/components/schemas/ErrorResponse'-run_test!endenddiff --git a/docs/api-reference/store.yaml b/docs/api-reference/store.yamlindex 139bf05e99..3a792a8038 100644--- a/docs/api-reference/store.yaml+++ b/docs/api-reference/store.yaml@@ -1270,35 +1270,31 @@ paths:schema:"$ref": "#/components/schemas/ErrorResponse""/api/v3/store/orders/{order_id}/payments":+ parameters:+ - name: x-spree-api-key+ in: header+ required: true+ schema:+ type: string+ - name: Authorization+ in: header+ required: true+ schema:+ type: string+ - name: order_id+ in: path+ description: Order number or ID+ required: true+ schema:+ type: stringget:- summary: List payments for an order+ summary: List paymentstags:- Paymentssecurity:- api_key: []bearer_auth: []- description: Returns all payments associated with the order- parameters:- - name: x-spree-api-key- in: header- required: true- schema:- type: string- - name: Authorization- in: header- required: false- schema:- type: string- - name: order_id- in: path- required: true- schema:- type: string- - name: order_token- in: query- required: false- schema:- type: string+ description: Returns a list of payments for the specified orderresponses:'200':description: payments found@@ -1311,121 +1307,46 @@ paths:type: arrayitems:"$ref": "#/components/schemas/StorePayment"- required:- - data+ meta:+ type: object'404':description: order not foundcontent:application/json:schema:"$ref": "#/components/schemas/ErrorResponse"- post:- summary: Create a payment- tags:- - Payments- security:- - api_key: []- bearer_auth: []- description: Creates a new payment for the order using the specified payment- method- parameters:- - name: x-spree-api-key- in: header- required: true- schema:- type: string- - name: Authorization- in: header- required: false- schema:- type: string- - name: order_id- in: path- required: true- schema:- type: string- - name: order_token- in: query- required: false- schema:- type: string- responses:- '201':- description: payment created- content:- application/json:- schema:- "$ref": "#/components/schemas/StoreOrder"- '422':- description: invalid payment method- content:- application/json:- schema:- "$ref": "#/components/schemas/ErrorResponse"- requestBody:- content:- application/json:- schema:- type: object- properties:- payment_method_id:- type: string- description: Payment method ID- amount:- type: number- description: Payment amount (optional, defaults to order total)- source_attributes:- type: object- description: Payment source details (card info, etc.)- properties:- number:- type: string- month:- type: string- year:- type: string- verification_value:- type: string- name:- type: string- required:- - payment_method_id"/api/v3/store/orders/{order_id}/payments/{id}":+ parameters:+ - name: x-spree-api-key+ in: header+ required: true+ schema:+ type: string+ - name: Authorization+ in: header+ required: true+ schema:+ type: string+ - name: order_id+ in: path+ description: Order number or ID+ required: true+ schema:+ type: string+ - name: id+ in: path+ description: Payment ID+ required: true+ schema:+ type: stringget:- summary: Get a payment+ summary: Get paymenttags:- Paymentssecurity:- api_key: []bearer_auth: []- description: Returns details of a specific payment- parameters:- - name: x-spree-api-key- in: header- required: true- schema:- type: string- - name: Authorization- in: header- required: false- schema:- type: string- - name: order_id- in: path- required: true- schema:- type: string- - name: id- in: path- required: true- description: Payment ID- schema:- type: string- - name: order_token- in: query- required: false- schema:- type: string+ description: Returns a single payment by IDresponses:'200':description: payment found@@ -3401,10 +3322,7 @@ components:properties:id:type: string- country_id:- type: string- nullable: true- state_id:+ state_abbr:type: stringnullable: truename:diff --git a/sdk/src/client.ts b/sdk/src/client.tsindex 0c4289eea8..d0061d8dc3 100644--- a/sdk/src/client.ts+++ b/sdk/src/client.ts@@ -9,7 +9,6 @@ import type {OrderListParams,AddLineItemParams,UpdateLineItemParams,- CreatePaymentParams,UpdateOrderParams,StoreProduct,StoreOrder,@@ -17,8 +16,8 @@ import type {StoreCountry,StoreTaxonomy,StoreTaxon,- StorePaymentMethod,StorePayment,+ StorePaymentMethod,StoreStore,StoreWishlist,StoreAddress,@@ -417,8 +416,8 @@ export class SpreeClient {list: (orderId: string,options?: RequestOptions- ): Promise<PaginatedResponse<StorePayment>> =>- this.request<PaginatedResponse<StorePayment>>(+ ): Promise<{ data: StorePayment[]; meta: object }> =>+ this.request<{ data: StorePayment[]; meta: object }>('GET',`/orders/${orderId}/payments`,options@@ -437,21 +436,12 @@ export class SpreeClient {`/orders/${orderId}/payments/${paymentId}`,options),-- /**- * Create a payment- */- create: (- orderId: string,- params: CreatePaymentParams,- options?: RequestOptions- ): Promise<StoreOrder> =>- this.request<StoreOrder>('POST', `/orders/${orderId}/payments`, {- ...options,- body: params,- }),};+ // ============================================+ // Payment Methods+ // ============================================+readonly paymentMethods = {/*** List available payment methods for an orderdiff --git a/sdk/src/types/generated/StoreStockLocation.ts b/sdk/src/types/generated/StoreStockLocation.tsindex 819257b976..b688dabfc3 100644--- a/sdk/src/types/generated/StoreStockLocation.ts+++ b/sdk/src/types/generated/StoreStockLocation.ts@@ -1,11 +1,10 @@-// Typelizer digest 4fb8ec178063634ed5f86f709232d848+// Typelizer digest ed60d1db9a86b2fed077b6da74418c28//// DO NOT MODIFY: This file was automatically generated by Typelizer.type StoreStockLocation = {id: string;- country_id: string | null;- state_id: string | null;+ state_abbr: string | null;name: string;address1: string | null;city: string | null;diff --git a/sdk/src/types/index.ts b/sdk/src/types/index.tsindex eeb86a37e2..3f470b5b91 100644--- a/sdk/src/types/index.ts+++ b/sdk/src/types/index.ts@@ -73,13 +73,6 @@ export interface UpdateLineItemParams {quantity: number;}-// Payment params-export interface CreatePaymentParams {- payment_method_id: string;- amount?: number;- source_attributes?: Record<string, unknown>;-}-// Address paramsexport interface AddressParams {firstname: string;