From b7bd3355f6d93d4151175fd5bcc7dd807d7dc254 Mon Sep 17 00:00:00 2001 From: vitkx Date: Mon, 20 Jan 2025 14:57:15 -0500 Subject: [PATCH] Email me --- app/controllers/spree/paypal_controller.rb | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/controllers/spree/paypal_controller.rb b/app/controllers/spree/paypal_controller.rb index bfb6aff..82e020e 100644 --- a/app/controllers/spree/paypal_controller.rb +++ b/app/controllers/spree/paypal_controller.rb @@ -28,6 +28,34 @@ def capture_order order.save order.next until order.completed? || order.errors.any? order.finalize! + begin + if params['order']['email_me'] + address = order.ship_address + gibbon = ::Gibbon::Request.new(api_key: SpreeMailchimpEcommerce.configuration.mailchimp_api_key) + gibbon.lists(::SpreeMailchimpEcommerce.configuration.mailchimp_list_id) + .members + .create( + body: { + email_address: order.email, + status: "subscribed", + merge_fields: { + FNAME: address.firstname, + LNAME: address.lastname, + ADDRESS: [ + address.address1, + address.address2, + address.city, + address.state_name, + address.zipcode, + address.country_name + ].compact.join(', '), + PHONE: address.phone + } + } + ) + end + rescue + end render json: { status: 'success', details: response }, status: :ok else render json: { error: 'Capture failed' }, status: :unprocessable_entity