Class: Centaman::Service::PurchaseMembership
- Inherits:
-
Centaman::Service
- Object
- Wrapper
- Centaman::Service
- Centaman::Service::PurchaseMembership
- Defined in:
- lib/centaman/service/purchase_membership.rb
Constant Summary
Constants inherited from Wrapper
Instance Attribute Summary collapse
-
#add_ons ⇒ Object
readonly
Returns the value of attribute add_ons.
-
#checkout_service ⇒ Object
readonly
Returns the value of attribute checkout_service.
-
#coupon ⇒ Object
readonly
Returns the value of attribute coupon.
-
#coupon_service ⇒ Object
readonly
Returns the value of attribute coupon_service.
-
#expiry_date ⇒ Object
readonly
Returns the value of attribute expiry_date.
-
#has_card_discount ⇒ Object
readonly
Returns the value of attribute has_card_discount.
-
#is_new ⇒ Object
readonly
Returns the value of attribute is_new.
-
#join_date ⇒ Object
readonly
Returns the value of attribute join_date.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#membership_type_id ⇒ Object
readonly
Returns the value of attribute membership_type_id.
-
#memberships ⇒ Object
readonly
Returns the value of attribute memberships.
-
#order_info ⇒ Object
readonly
Returns the value of attribute order_info.
-
#payment_reference ⇒ Object
readonly
Returns the value of attribute payment_reference.
-
#purchaser_renewal ⇒ Object
readonly
Returns the value of attribute purchaser_renewal.
Attributes inherited from Wrapper
#api_password, #api_token, #api_url, #api_username, #proxie_host, #proxie_password, #proxie_port, #proxie_user
Instance Method Summary collapse
- #after_init(args = {}) ⇒ Object
-
#build_membership_request ⇒ Object
def new_membership_request p “building new_membership_request” new_members.map do |m| order_info.add_ons_for_member(add_ons, m.member_type).each do |ao| @new_memberships << membership_payload(m, ao) end end @new_memberships = @new_memberships.uniq end.
- #card_discount_args(add_on) ⇒ Object
- #coupon_args(add_on) ⇒ Object
- #empty_card_args ⇒ Object
- #empty_coupon_args ⇒ Object
- #endpoint ⇒ Object
- #membership_payload(member, add_on) ⇒ Object
- #options_hash ⇒ Object
Methods inherited from Centaman::Service
#after_post, #fetch_all, #post, #put
Methods inherited from Wrapper
#generate_token, #headers, #initialize, #options, #payload, #payload_key, #proxy_hash, #wrap_request_in_case_of_timeout
Constructor Details
This class inherits a constructor from Centaman::Wrapper
Instance Attribute Details
#add_ons ⇒ Object (readonly)
Returns the value of attribute add_ons.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def add_ons @add_ons end |
#checkout_service ⇒ Object (readonly)
Returns the value of attribute checkout_service.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def checkout_service @checkout_service end |
#coupon ⇒ Object (readonly)
Returns the value of attribute coupon.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def coupon @coupon end |
#coupon_service ⇒ Object (readonly)
Returns the value of attribute coupon_service.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def coupon_service @coupon_service end |
#expiry_date ⇒ Object (readonly)
Returns the value of attribute expiry_date.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def expiry_date @expiry_date end |
#has_card_discount ⇒ Object (readonly)
Returns the value of attribute has_card_discount.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def has_card_discount @has_card_discount end |
#is_new ⇒ Object (readonly)
Returns the value of attribute is_new.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def is_new @is_new end |
#join_date ⇒ Object (readonly)
Returns the value of attribute join_date.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def join_date @join_date end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def members @members end |
#membership_type_id ⇒ Object (readonly)
Returns the value of attribute membership_type_id.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def membership_type_id @membership_type_id end |
#memberships ⇒ Object (readonly)
Returns the value of attribute memberships.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def memberships @memberships end |
#order_info ⇒ Object (readonly)
Returns the value of attribute order_info.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def order_info @order_info end |
#payment_reference ⇒ Object (readonly)
Returns the value of attribute payment_reference.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def payment_reference @payment_reference end |
#purchaser_renewal ⇒ Object (readonly)
Returns the value of attribute purchaser_renewal.
3 4 5 |
# File 'lib/centaman/service/purchase_membership.rb', line 3 def purchaser_renewal @purchaser_renewal end |
Instance Method Details
#after_init(args = {}) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/centaman/service/purchase_membership.rb', line 7 def after_init(args={}) @payment_reference = args[:payment_reference] @order_info = args[:order_info] @is_new = args.fetch(:is_new, false) @has_card_discount = @order_info.fnbo_discount @checkout_service = args[:checkout_service] @coupon_service = args[:coupon_service] @membership_type_id = @order_info.membership_type_id @members = args.fetch(:members, []) @add_ons = @checkout_service.add_ons @memberships = [] @coupon = @coupon_service.valid_coupon @join_date = args.fetch(:join_date, nil) @expiry_date = args.fetch(:expiry_date, nil) @purchaser_renewal = args.fetch(:purchaser_renewal, false) end |
#build_membership_request ⇒ Object
def new_membership_request
p "building new_membership_request"
new_members.map do |m|
order_info.add_ons_for_member(add_ons, m.member_type).each do |ao|
@new_memberships << membership_payload(m, ao)
end
end
@new_memberships = @new_memberships.uniq
end
107 108 109 110 111 112 113 114 115 |
# File 'lib/centaman/service/purchase_membership.rb', line 107 def build_membership_request p "build request" members.map do |m| order_info.add_ons_for_member(add_ons, m.member_type).each do |ao| @memberships << membership_payload(m, ao) end end @memberships end |
#card_discount_args(add_on) ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/centaman/service/purchase_membership.rb', line 58 def card_discount_args(add_on) return {} unless add_on.add_on_type == 'primary' { 'CardDiscount': { 'DiscountAmount': checkout_service.fnbo_amount, 'StockID': checkout_service.fnbo_stock_id } } end |
#coupon_args(add_on) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/centaman/service/purchase_membership.rb', line 47 def coupon_args(add_on) return {} unless coupon_service.coupon_applies(add_on) { 'Coupon': { "CouponCode": coupon.coupon_code, "DiscountAmount": coupon_service.amount_saved(add_on), "StockID": coupon.coupon_stock_id } } end |
#empty_card_args ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/centaman/service/purchase_membership.rb', line 78 def empty_card_args { 'CardDiscount': { 'DiscountAmount': 0, 'StockID': nil } } end |
#empty_coupon_args ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/centaman/service/purchase_membership.rb', line 68 def empty_coupon_args { 'Coupon': { "CouponCode": nil, "DiscountAmount": 0, "StockID": nil } } end |
#endpoint ⇒ Object
24 25 26 |
# File 'lib/centaman/service/purchase_membership.rb', line 24 def endpoint "/member_services/Membership?isNew=#{is_new}" end |
#membership_payload(member, add_on) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/centaman/service/purchase_membership.rb', line 28 def membership_payload(member, add_on) p 'dates' p join_date, expiry_date payload = { 'MemberCode': member.id, 'TypeCode': add_on.id, 'Cost': add_on.cost, 'Tax': checkout_service.add_on_tax(add_on), 'Paid': add_on.pay_price, 'PackageID': membership_type_id, 'PurchaserRenewal': purchaser_renewal, 'PaymentGatewayReference': payment_reference, 'JoinDate': join_date, 'ExpiryDate': expiry_date }.compact payload = coupon.present? ? payload.merge(coupon_args(add_on)) : payload payload = has_card_discount ? payload.merge(card_discount_args(add_on)) : payload end |
#options_hash ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/centaman/service/purchase_membership.rb', line 117 def p "*** PAYLOAD ***" p build_membership_request memberships.to_json # p @new_memberships if is_new # p @renewal_memberships if !is_new end |