Class: SolidusPaybright::ParamsHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/solidus_paybright/params_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(payment) ⇒ ParamsHelper

Returns a new instance of ParamsHelper.

Parameters:

  • payment (Spree::Payment)

    The payment in question



6
7
8
# File 'lib/solidus_paybright/params_helper.rb', line 6

def initialize(payment)
  @payment = payment
end

Instance Method Details

#build_redirect_paramsHash

Returns The parameters to be used on the Paybright redirect call.

Returns:

  • (Hash)

    The parameters to be used on the Paybright redirect call



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/solidus_paybright/params_helper.rb', line 11

def build_redirect_params
  bill_address = order.bill_address
  ship_address = order.ship_address

  params = {
    # mandatory parameters
    "x_account_id" => credentials[:api_key],
    "x_amount" => order.total.to_money.to_s,
    "x_currency" => order.currency,
    "x_reference" => @payment.id,
    "x_shop_country" => credentials[:shop_country_code],
    "x_shop_name" => credentials[:shop_name],
    "x_test" => credentials[:test_mode].to_s,
    "x_url_callback" => paybright_callback_url,
    "x_url_cancel" => paybright_cancel_url(@payment),
    "x_url_complete" => paybright_complete_url,
    # optional parameters
    "x_description" => "Order ##{order.number}",
    "x_customer_email" => order.email,
    "x_customer_first_name" => bill_address.firstname,
    "x_customer_last_name" => bill_address.lastname,
    "x_customer_billing_address1" => bill_address.address1,
    "x_customer_billing_address2" => bill_address.address2,
    "x_customer_billing_city" => bill_address.city,
    "x_customer_billing_company" => bill_address.company,
    "x_customer_billing_country" => bill_address.country.iso,
    "x_customer_billing_phone" => bill_address.phone,
    "x_customer_billing_state" => bill_address.state.try(:name),
    "x_customer_billing_zip" => bill_address.zipcode,
    "x_customer_shipping_address1" => ship_address.address1,
    "x_customer_shipping_address2" => ship_address.address2,
    "x_customer_shipping_city" => ship_address.city,
    "x_customer_shipping_company" => ship_address.company,
    "x_customer_shipping_country" => ship_address.country.iso,
    "x_customer_shipping_first_name" => ship_address.firstname,
    "x_customer_shipping_last_name" => ship_address.lastname,
    "x_customer_shipping_phone" => ship_address.phone,
    "x_customer_shipping_state" => ship_address.state.try(:name),
    "x_customer_shipping_zip" => ship_address.zipcode
  }

  params.keep_if { |_, value| value.present? }
  params.merge("x_signature" => signing_helper.params_signature(params))
end