Download Cyclos 4 PRO Documentation

Transcript
def recordId = request.parameters.recordId as Long
def payerId = request.parameters.PayerID
// No record?
if (recordId == null) {
return "[ERROR] " +
(scriptParameters.'error.invalidRequest' ?: "Invalid request")
}
// Find the corresponding record
UserRecord userRecord = record.find(applicationHandler.idMask.remove(recordId))
if (userRecord == null) {
return "[ERROR] " +
(scriptParameters.'error.transactionNotFound' ?: "Transaction not found")
}
def wrapped = scriptHelper.wrap(userRecord)
if (request.parameters.cancel) {
// The operation has been canceled. Remove the record and send a message.
record.remove(userRecord)
return "[WARN]" + scriptParameters.'message.canceled'
?: "You have cancelled the operation.\nFeel free to start again if needed."
} else {
// Execute the payment
try {
def json = paypal.execute(payerId, userRecord)
if (json.state == 'approved') {
return scriptParameters.'message.done'
?: "You have successfully completed the payment. Thank you."
} else {
return "[ERROR] " + scriptParameters.'error.notApproved'
?: "The payment was not approved"
}
} catch (Exception e) {
return "[ERROR] " + scriptParameters.'error.payment'
?: "There was an error while processing the payment. Please, try again."
}
}
Create the custom operation
Under System > Tools > Custom operations, create a new one with the following
characteristics:
• Name: Buy units with PayPal (can be changed – will be the label displayed on the menu)
• Enabled: yes
• Scope: user
• Script: Buy units with PayPal
• Script parameters: leave empty
• Result type: External redirect
• Has file upload: no
Cyclos 4 PRO Documentation
65