I can't set the item summary in set express checkoput. L_NAME0=A caused error
def strUsername = "***"
def strPassword = "***"
def strSignature = "***"
def strCredentials = "USER=" + strUsername + "&PWD=" + strPassword + "&SIGNATURE=" + strSignature
def strNVPSandboxServer = "https://api-3t.sandbox.paypal.com/nvp";
def user = session.userId +","+amt + "," + receiver + "," + address + "," + opt
def successUrl = '***
def cancelUrl = '***'
def strAPIVersion = "56.0"
def strNVP = strCredentials + "&METHOD=SetExpressCheckout&AMT=" + totalamount +"&PAYMENTACTION=Sale&RETURNURL="+ successUrl+"&CANCELURL="+ cancelUrl +"&CURRENCYCODE=SGD&ITEMAMT="+totalamount+"&L_NAME0=OHN&VERSION=" + strAPIVersion
Try updating def strAPIVersion = "56.0" to def strAPIVersion = "76.0" I think the advanced features a not available in the 56 version. I used the default set by Paypal as a test
&L_PAYMENTREQUEST_0_NAME0=10% Decaf Kona Blend Coffee
&L_PAYMENTREQUEST_0_NUMBER0=623083
&L_PAYMENTREQUEST_0_DESC0=Size: 8.8-oz
&L_PAYMENTREQUEST_0_AMT0=9.95
&L_PAYMENTREQUEST_0_QTY0=2
&L_PAYMENTREQUEST_0_NAME1=Coffee Filter bags
&L_PAYMENTREQUEST_0_NUMBER1=623084
&L_PAYMENTREQUEST_0_DESC1=Size: Two 24-piece boxes
&L_PAYMENTREQUEST_0_AMT1=39.70
&L_PAYMENTREQUEST_0_QTY1=2
&PAYMENTREQUEST_0_ITEMAMT=99.30
&PAYMENTREQUEST_0_TAXAMT=2.58
&PAYMENTREQUEST_0_SHIPPINGAMT=3.00
&PAYMENTREQUEST_0_HANDLINGAMT=2.99
&PAYMENTREQUEST_0_SHIPDISCAMT=-3.00
&PAYMENTREQUEST_0_INSURANCEAMT=1.00
&PAYMENTREQUEST_0_AMT=105.87
&ALLOWNOTE=1
Related
I'm trying to calculate a hash for a payment form but I get the error:
no implicit conversion of Fixnum into String
so I interpret this that I'm trying to do math calculation on what is text. But how should I correct my code?
The instructions from the payment merchant are:
hash = SHA1(salt + "|" + description + "|" + amount + "|" + currency +
"|" + transaction_type)
So in my controller I have:
def checkout
#organization = Organization.new(organizationnew_params)
if #organization.save
#organization.members.each do |single_member|
single_member.send_activation_email
end
#amount = 100.00
#currency = "EUR"
#description = #organization.id
#transaction_description = "My description"
#transaction_type = "S"
### LINE BELOW HAS THE HASH, WHICH REFERS TO THE PRIVATE METHOD BELOW ###
#hash = hash(#description, #amount, #currency, #transaction_type)
render 'checkout'
else
render 'new_premium'
end
end
private
def hash(description, amount, currency, transaction_type)
#hash = SHA1(SALT + "|" + description + "|" + amount + "|" + currency + "|" + transaction_type)
end
In an initializer I have defined SALT (as well as my merchant_id which is used in the form that is posted to the merchant in the checkout view).
Writing this will be better.
hash = SHA1([salt, description, amount.to_s, currency,transaction_type].join("|"))
You interpreted it wrongly, it's the other way round. You're trying to use a number as a string.
Try to explicitely convert the number in to a string, like so:
#hash = SHA1(SALT + "|" + description + "|" + amount.to_s + "|" + currency + "|" + transaction_type)
As I don't know what all the variables' types are, you might have to add another to_s to a non-string.
The error indicates that you are adding a number to a string, I think the problem is that "amount" is a number which you are adding to a string. you just have to change that:
#hash = SHA1(SALT + "|" + description + "|" + amount.to_s + "|" + currency + "|" + transaction_type)
the :to_s method will convert amount into string. (if there are other numbers just do the same.)
Or you can do this with string interpolation:
#hash = SHA1("#{SALT}|#{description}|#{amount}|#{currency}|#{transaction_type}")
I want to create an object(say Y) of another model as soon as object(say X) of one model is created. Object Y needs to take some attributes of object X that was created. So the after_save method basically should have code equivalent to New Y(Object X). My doubt is how to pass the object X as a parameter to the New() call.
You could always create Y and then assign values to it's properties, then call save on Y.
def after_save_func
y = y.new
y.val1 = self.val1
y.val2 - self.val2
y.save
end
But this method is going to be called after every save, which seems wrong more like after_create would be the best?
I am not sure if the below code i Wrote finally is a good solution by design standards or not. But it seems to work for my requirements:
def create_wc
Workcategory.delete_all(rfsestimationid: self.id)
#workcategory = Workcategory.new()
#workcategory.name = self.name + "_" + "#{self.number}" + "_Analysis"
#workcategory.hours = self.rfstaskset.analysis_hours
#workcategory.rfsestimationid = self.id
#workcategory.save
#workcategory = Workcategory.new()
#workcategory.name = self.name + "_" + "#{self.number}" + "_Design"
#workcategory.hours = self.rfstaskset.design_hours
#workcategory.rfsestimationid = self.id
#workcategory.save
#workcategory = Workcategory.new()
#workcategory.name = self.name + "_" + "#{self.number}" + "_Test"
#workcategory.hours = self.rfstaskset.test_hours
#workcategory.rfsestimationid = self.id
#workcategory.save
#workcategory = Workcategory.new()
#workcategory.name = self.name + "_" + "#{self.number}" + "_Build"
#workcategory.hours = self.rfstaskset.test_hours
#workcategory.rfsestimationid = self.id
#workcategory.save
#workcategory = Workcategory.new()
#workcategory.name = self.name + "_" + "#{self.number}" + "_UATSupport"
#workcategory.hours = self.rfstaskset.UATSupport_hours
#workcategory.rfsestimationid = self.id
#workcategory.save
#workcategory = Workcategory.new()
#workcategory.name = self.name + "_" + "#{self.number}" + "_DepSupport"
#workcategory.hours = self.rfstaskset.DepSupport_hours
#workcategory.rfsestimationid = self.id
#workcategory.save
end
The workcategory objects are deleted each time, the parent object is updated and rebuilt in the above code.
This code is executed as an after_save operation.
I have a system that an supposed to give my partner a public key to decry-pt the text. What I want is how to sign that text using my private key. This is how am doing it but it has failed.
require 'openssl'
require 'base64'
require 'digest/sha1'
#date = Date.today.strftime("%m/%d/%Y")
text_to_sign = "#{#order.phone_no}" + "#{#order.name}" + "#{#order.pay_type}" + "#{#order.pay_type}" + "1" + "MABIRA" + "81W30DI846" + "#{#date}" + "PULL" + "1" + "#{#cart.total_price}" + "#{#order.phone_no}" + ""
cipher = OpenSSL::Cipher.new 'aes-256-cbc'
cipher.encrypt
cipher.key = cipher.random_key
cipher.iv = cipher.random_iv
encrypted = cipher.update(text_to_sign) + cipher.final
private_key = OpenSSL::PKey::RSA.new(File.read('Private.key'), password)
ciphertext = private_key.private_encrypt(encrypted)
ciphertext.encoding
signed_text = Base64.encode64(ciphertext).gsub("\n", '')
puts signed_text
signed_text
In my controller I am trying to do a bulk insert into a table, in my first attempt it works but the names somehow get mangled as the following: (loop runs 24 times which is what I want)
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11
test-port-name-0-1-2-3-4-5-6-7-8-9-10
test-port-name-0-1-2-3-4-5-6-7-8-9
test-port-name-0-1-2-3-4-5-6-7-8
test-port-name-0-1-2-3-4-5-6
test-port-name-0-1-2-3-4-5-6-7
test-port-name-0-1-2-3-4-5
test-port-name-0-1-2-3-4
test-port-name-0-1-2
test-port-name-0-1-2-3
test-port-name-0
test-port-name-0-1
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22
test-port-name-0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23
instead of test-port-name-0 .... test-port-name-23
def bulk_port_import
if request.post?
#attempt create
count = 0
for i in 1..session[:no_ports]
params[:dp][:name] = params[:dp][:name] + '-' + count.to_s
#dp = DevicePort.create params[:dp]
count = count + 1
end
end
#success = "Saved." if #dp.valid?
#error = ""
#dp.errors.each_full {|e| #error += e + ", "}
redirect_to '/device/update/' + params[:dp][:device_id]
end
Different attempt:
def bulk_port_import
if request.post?
#attempt create
i = 0
while i < session[:no_ports] do
params[:dp][:name] = params[:dp][:name] + '-' + i.to_s
#dp = DevicePort.create params[:dp]
i++
end
end
session.delete(:no_ports)
#success = "Saved." if #dp.valid?
#error = ""
#dp.errors.each_full {|e| #error += e + ", "}
redirect_to '/device/update/' + params[:dp][:device_id]
end
but with this I get syntax error, unexpected kEND and I can't see what I'm doing wrong in either case, it's probably something stupid, again.
Its because you are changing params[:dp][:name] in the loop
def bulk_port_import
if request.post?
#attempt create
count = 0
for i in 1..session[:no_ports]
dp_name = params[:dp][:name] + '-' + count.to_s
#dp = DevicePort.create(params[:dp].merge(:name => dp_name))
count = count + 1
end
end
#success = "Saved." if #dp.valid?
#error = ""
#dp.errors.each_full {|e| #error += e + ", "}
redirect_to '/device/update/' + params[:dp][:device_id]
end
I have some problem to activate qrcode 0.3 plugin. I already install on my project, and how to get print qrcode?
This is my code
def beforeInsert() {
Integer count = Batch.count()+1
String bc = sprintf('%04d',count)
if( packNoLevel1 != null){
number = prodDate.format('MM/dd/yy') + '/' + packNoLevel1 + '/' + item.code + '/' + bc
}else{
number = prodDate.format('MM/dd/yy') + '/' + packNoLevel2 + '/' + item.code + '/' + bc
}
and how to generate number to qrcode ??
thanks..
First is this beforeInsert an event in your domain? If so generating qr inside your domain does not help with rendering it. Either you need to move that logic into your controller or save that number in database and use it later from a controller when you want to display the qrcode.
I assumed you were able to move the logic into a controller then you just need to pass that number into your view and the view will render the qrCode for you based on that number.
YourController.groovy
def show() {
// this logic needs be tweaked if you decide to have it in controller
//Integer count = Batch.count()+1
//String bc = sprintf('%04d',count)
// if( packNoLevel1 != null){
// number = prodDate.format('MM/dd/yy') + '/' + packNoLevel1 + '/' + item.code + '/' + bc
// }else{
// number = prodDate.format('MM/dd/yy') + '/' + packNoLevel2 + '/' + item.code + '/' + bc
// }
def number = calculateMe()
[...,qrNumber:number]
}
list.gsp
<qrcode:image text="${qrNumber}"/>