So I’ve been trying to get Substruct to use PayPal Pro instead of Authorize.net as the payment gateway. There are a couple of options out there to do this namely
vPayPal which I didn’t have any luck with and
elTechs PayPal plugin which is the option I finally got working
The problems I had were all due to bugs in soap4r 1.5.5, the so called stable release.
So here is how you tweak soap4r to make it work… (If you want to be lazy download my patched copy)
- Skip 1.5.5 and grab the code that is sitting on the trunk and make these next two updates
- Apply patch 1629 to complexContent.rb that lives in lib/wsdl/xmlSchema/complexContent.rb
- Change wsdl/soap/classDefCreator.rb as follows
Comment out the type = nil line and uncomment the type = create_class_name line)if element.type == XSD::AnyTypeName type = nil elsif klass = element_basetype(element) type = klass.name elsif element.type type = create_class_name(element.type) else # type = nil # do we define a class for local complexType from it's name? type = create_class_name(element.name) end
- You can now go ahead and run install.rb to install the package.
- Follow the rest of the instructions from the PayPal plugin
- Success!
Big thanks to Brenden Wilson as without his post I never would have gotten this running (being a complete RubyNoobie)
The next step is getting all of this working from within Substruct.
Change the finish_order method in store_controller.rb to
def finish_order
@title = "Thanks for your order!"
@order = find_order
# If there's no order redirect to index
if @order == nil
redirect_to_index and return
end
@transaction_details = {
:firstName => @order.billing_address.first_name,
:lastName => @order.billing_address.last_name,
:ip => "127.0.0.1",
:amount => @order.total.to_s,
:itemName => @order.order_number,
:addressName => "Billing",
:street1 => @order.billing_address.address,
:street2 => "",
:cityName => @order.billing_address.city,
:postalCode => @order.billing_address.zip,
:stateOrProvince => @order.billing_address.state,
:country => "US",
:creditCardType => get_credit_card_type(@order.account.cc_number),
:creditCardNumber => @order.account.cc_number,
:cVV2 => @order.account.credit_ccv,
:expMonth => @order.account.expiration_month,
:expYear => @order.account.expiration_year
}
result = Paypal.directauth(@transaction_details)
if(result.ack == "Success")
@payment_message = "Card processed successfully: #{result.transactionID}"
# Save transaction id for later
@order.auth_transaction_id = result.transactionID
logger.info("nnORDER TRANSACTION ID - #{result.transactionID}nn")
# Set completed
@order.cleanup_successful
# Send success message
@order.deliver_receipt
clear_cart_and_order(false)
else
# Order failed - store transaction id
# @order.auth_transaction_id = result.transactionID
@order.cleanup_failed(result.ack)
# Send failed message
@order.deliver_failed
# Log errors
logger.error("nn[ERROR] FAILED ORDER n")
logger.error(result)
logger.error("nn")
# Redirect to checkout and allow them to enter info again.
error_message = "#{result.errors.longMessage}"
error_message << "Try again or contact us for further assistance."
redirect_to_checkout(error_message)
end
end