This commit is contained in:
24c02 2025-12-18 15:05:51 -05:00
parent 958878dc18
commit 97a1267f95
3 changed files with 31 additions and 13 deletions

View file

@ -42,6 +42,7 @@ class USPS::Indicium < ApplicationRecord
belongs_to :payment_account, foreign_key: :usps_payment_account_id
belongs_to :letter, optional: true
belongs_to :hcb_payment_account, class_name: "HCB::PaymentAccount", optional: true
def buy!(payment_token = nil)
raise ArgumentError, "for what?" unless letter

View file

@ -0,0 +1,29 @@
<div class="flex flex-col gap-2">
<%= form_with(url: buy_indicia_letter_path(letter), method: :post) do |form| %>
<div class="form-group">
<label>USPS Payment Account</label>
<%= form.collection_select :usps_payment_account_id,
USPS::PaymentAccount.all,
:id,
:name,
{ prompt: "Select a payment account", selected: USPS::PaymentAccount.first&.id },
{ required: true } %>
</div>
<% if current_user.hcb_payment_accounts.any? %>
<div class="form-group">
<label>Pay with HCB Organization</label>
<%= form.collection_select :hcb_payment_account_id,
current_user.hcb_payment_accounts,
:id,
:organization_name,
{ prompt: "Select an organization" },
{ required: true } %>
</div>
<% else %>
<p class="text-sm text-gray-600">
<%= link_to "Connect your HCB account", new_back_office_hcb_oauth_connection_path %> to purchase indicia.
</p>
<% end %>
<%= form.submit "Buy Indicia", class: "primary", disabled: current_user.hcb_payment_accounts.empty? %>
<% end %>
</div>

View file

@ -92,19 +92,7 @@
Indicia (Metered) - Not Purchased Yet
</p>
<% if @letter.batch_id.nil? %>
<div class="flex items-center gap-4">
<%= form_with(url: buy_indicia_letter_path(@letter), method: :post) do |form| %>
<div class="form-group">
<%= form.collection_select :usps_payment_account_id,
USPS::PaymentAccount.all,
:id,
:name,
{ prompt: "Select a payment account", selected: USPS::PaymentAccount.first&.id },
{ required: true } %>
</div>
<%= form.submit "Buy Indicia", class: "primary" %>
<% end %>
</div>
<%= render 'buy_indicia_form', letter: @letter %>
<% end %>
<% end %>
<% elsif @letter.postage_type == "international_origin" %>