class Heartcheck::Checks::Paypal

Public Instance Methods

validate() click to toggle source
# File lib/heartcheck/checks/paypal.rb, line 8
def validate
  services.each do |service|
    configure_paypal_api(service) if change_configs?(service)

    unless create_payment(service)
      @errors << @payment.error
    end
  rescue StandardError => e
    @errors << e.message
  end
end

Private Instance Methods

change_configs?(service) click to toggle source
# File lib/heartcheck/checks/paypal.rb, line 39
def change_configs?(service)
  service[:client_id] && service[:client_secret] && service[:mode]
end
configure_paypal_api(service) click to toggle source
# File lib/heartcheck/checks/paypal.rb, line 29
def configure_paypal_api(service)
   PayPal::SDK::REST.set_config(
      {
        client_id: service[:client_id],
        client_secret: service[:client_secret],
        mode: service[:mode]
      }
    )
end
create_payment(service) click to toggle source
# File lib/heartcheck/checks/paypal.rb, line 22
def create_payment(service)
  order = service[:order] || dumb_order

  @payment = Payment.new(order)
  @payment.create
end
dumb_order() click to toggle source
# File lib/heartcheck/checks/paypal.rb, line 43
def dumb_order
  {
    intent: 'sale',
    payer: { payment_method: 'paypal' },
    redirect_urls: {
      return_url: 'http://localhost:3000/payment/execute',
      cancel_url: 'http://localhost:3000/'
    },
    transactions: [
      {
        item_list: {
          items: [
            {
              name: 'blevs',
              sku: 'jettyphon',
              price: '7',
              currency: 'BRL',
              quantity: 1
            }
          ]
        },
        amount: { total: '7', currency: 'BRL' },
        description: 'Its just a test description.'
      }
    ]
  }
end