def get(self):
        if self.has_session_error():
            return
    
    
        paypalResponse = EC.get_express_checkout_details(self.request.get('token'))
        
        hasError = ErrorOperation.has_get_error(self.response, paypalResponse, 'GetExpressCheckoutDetails')
        if hasError:
            return


        contents = urlparse.parse_qs(paypalResponse.content)
        
        params = { # システムまわり
                           'postUrl': URL_PAYMENT + '?' + self.request.query_string,
                           
                           # 顧客情報
                           'email': contents['EMAIL'][0],
                           'firstname': contents['FIRSTNAME'][0],
                           'lastname': contents['LASTNAME'][0],
                           'shipToName': contents['PAYMENTREQUEST_0_SHIPTONAME'][0], # 姓名が入る
                           'shipToStreet': contents['PAYMENTREQUEST_0_SHIPTOSTREET'][0],
                           'shipToStreet2': contents['PAYMENTREQUEST_0_SHIPTOSTREET2'][0] if 'PAYMENTREQUEST_0_SHIPTOSTREET2' in contents else '',
                           'shipToCity': contents['PAYMENTREQUEST_0_SHIPTOCITY'][0],
                           'shipToState': contents['PAYMENTREQUEST_0_SHIPTOSTATE'][0],
                           'shipToZip': contents['PAYMENTREQUEST_0_SHIPTOZIP'][0],
                           # 日本では取得できない?
                           'shipToPhoneNo': contents['PAYMENTREQUEST_0_SHIPTOPHONENUM'][0] if 'PAYMENTREQUEST_0_SHIPTOPHONENUM' in contents else '',
                           
                           # 商品情報
                           'amount': contents['PAYMENTREQUEST_0_AMT'][0],
                           'itemAmount': contents['PAYMENTREQUEST_0_ITEMAMT'][0],
                           'shippingAmount': contents['PAYMENTREQUEST_0_SHIPPINGAMT'][0],
                           'taxAmount': contents['PAYMENTREQUEST_0_TAXAMT'][0],
                           'itemName': contents['L_PAYMENTREQUEST_0_NAME0'][0],
                           'itemUnitPrice': contents['L_PAYMENTREQUEST_0_AMT0'][0],
                           'quantity': contents['L_PAYMENTREQUEST_0_QTY0'][0],
                           'tax': contents['L_PAYMENTREQUEST_0_TAXAMT0'][0],
                           
                           # トランザクション情報:この時点では取得できない
                           #'transactionId': contents['PAYMENTREQUEST_0_TRANSACTIONID'][0],
                           #'requestId': contents['PAYMENTREQUEST_0_PAYMENTREQUESTID'][0],
                         }

        self.response.out.write(template.render('html/confirm.html',{'params': params,}))
    def post(self):
    
        if self.has_session_error():
            return
    
    
        payerId = self.request.get('PayerID')
        souvenirInfo = Souvenir.get_souvenir()
        
        
        # もう一度 GetExpressCheckoutで支払額合計を取得する
        paypalResponse = EC.get_express_checkout_details(self.request.get('token'))
        hasGetError = ErrorOperation.has_get_error(self.response, paypalResponse, 'GetExpressCheckoutDetails')
        if hasGetError:
            return
            
        contents = urlparse.parse_qs(paypalResponse.content)
            
        # get時と金額を変えてもエラーも何も出ずに決済されるので、そこが怖い...
        nvpParams = { 'PAYERID': payerId,
                      'PAYMENTREQUEST_0_PAYMENTACTION': 'Sale',
                      'PAYMENTREQUEST_0_AMT': contents['PAYMENTREQUEST_0_AMT'][0],
                      'PAYMENTREQUEST_0_CURRENCYCODE': souvenirInfo['currency'],
                     }
        
        paypalResponse = EC.do_express_checkout_payment(self.request.get('token'),
                                                        nvpParams
                                                       )
        

        hasDoError = ErrorOperation.has_do_error(self.response, paypalResponse, 'DoExpressCheckoutPayment')
        if hasDoError:
            return
        

        self.response.out.write(template.render('html/success.html',{}))