net.groupbuy.plugin.paypal.PaypalController.java Source code

Java tutorial

Introduction

Here is the source code for net.groupbuy.plugin.paypal.PaypalController.java

Source

/*
 * Copyright 2005-2013 shopxx.net. All rights reserved.
 * Support: http://www.shopxx.net
 * License: http://www.shopxx.net/license
 */
package net.groupbuy.plugin.paypal;

import java.math.BigDecimal;

import javax.annotation.Resource;

import net.groupbuy.Message;
import net.groupbuy.controller.admin.BaseController;
import net.groupbuy.entity.PluginConfig;
import net.groupbuy.plugin.PaymentPlugin;
import net.groupbuy.plugin.PaymentPlugin.FeeType;
import net.groupbuy.plugin.paypal.PaypalPlugin.Currency;
import net.groupbuy.service.PluginConfigService;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

/**
 * Controller - Paypal
 * 
 * @author SHOP++ Team
 * @version 3.0
 */
@Controller("adminPaypalController")
@RequestMapping("/admin/payment_plugin/paypal")
public class PaypalController extends BaseController {

    @Resource(name = "paypalPlugin")
    private PaypalPlugin paypalPlugin;
    @Resource(name = "pluginConfigServiceImpl")
    private PluginConfigService pluginConfigService;

    /**
     * 
     */
    @RequestMapping(value = "/install", method = RequestMethod.POST)
    public @ResponseBody Message install() {
        if (!paypalPlugin.getIsInstalled()) {
            PluginConfig pluginConfig = new PluginConfig();
            pluginConfig.setPluginId(paypalPlugin.getId());
            pluginConfig.setIsEnabled(false);
            pluginConfigService.save(pluginConfig);
        }
        return SUCCESS_MESSAGE;
    }

    /**
     * ?
     */
    @RequestMapping(value = "/uninstall", method = RequestMethod.POST)
    public @ResponseBody Message uninstall() {
        if (paypalPlugin.getIsInstalled()) {
            PluginConfig pluginConfig = paypalPlugin.getPluginConfig();
            pluginConfigService.delete(pluginConfig);
        }
        return SUCCESS_MESSAGE;
    }

    /**
     * 
     */
    @RequestMapping(value = "/setting", method = RequestMethod.GET)
    public String setting(ModelMap model) {
        PluginConfig pluginConfig = paypalPlugin.getPluginConfig();
        model.addAttribute("currencies", Currency.values());
        model.addAttribute("feeTypes", FeeType.values());
        model.addAttribute("pluginConfig", pluginConfig);
        return "/net/shopxx/plugin/paypal/setting";
    }

    /**
     * 
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String update(String paymentName, String partner, Currency currency, FeeType feeType, BigDecimal fee,
            String logo, String description, @RequestParam(defaultValue = "false") Boolean isEnabled, Integer order,
            RedirectAttributes redirectAttributes) {
        PluginConfig pluginConfig = paypalPlugin.getPluginConfig();
        pluginConfig.setAttribute(PaymentPlugin.PAYMENT_NAME_ATTRIBUTE_NAME, paymentName);
        pluginConfig.setAttribute("partner", partner);
        pluginConfig.setAttribute("currency", currency.toString());
        pluginConfig.setAttribute(PaymentPlugin.FEE_TYPE_ATTRIBUTE_NAME, feeType.toString());
        pluginConfig.setAttribute(PaymentPlugin.FEE_ATTRIBUTE_NAME, fee.toString());
        pluginConfig.setAttribute(PaymentPlugin.LOGO_ATTRIBUTE_NAME, logo);
        pluginConfig.setAttribute(PaymentPlugin.DESCRIPTION_ATTRIBUTE_NAME, description);
        pluginConfig.setIsEnabled(isEnabled);
        pluginConfig.setOrder(order);
        pluginConfigService.update(pluginConfig);
        addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
        return "redirect:/admin/payment_plugin/list.jhtml";
    }

}