在沙盒中使用的Rest API应用程序'但不是' Live'

时间:2015-10-02 17:45:46

标签: python django rest paypal live

出于某种原因我的应用使用PayPal REST API无法在实时模式下工作。这是我在Apache服务器上遇到的错误:

[:error] [pid 29701]警告:root:未在实时模式下记录完整的请求/响应标头和正文以确保合规性

这是我的代码,我使用Django:

def payPaypal(sku, price, ship_code):
        has_paypal_error = False
        paypal_approval_url = None
        paypalrestsdk.configure({
                'mode': settings.PAYPAL_STATUS, # live
                'client_id': settings.PAYPAL_LIVE_CLIENT_ID, 
                'client_secret': settings.PAYPAL_LIVE_CLIENT_SECRET 
        })

        payment = paypalrestsdk.Payment({
                "intent": "sale",
                "payer": {
                        "payment_method": "paypal" },
                "redirect_urls": {
                        "return_url": "mysite_url/thanks",
                        "cancel_url": "mysite_url" },

                "transactions": [ {
                        "amount": {
                                "total": price[ship_code].amount,
                                "currency": price[ship_code].currency },
                        "description": "my description.",
                        "item_list": {
                                "items": [ {
                                        "name": "name description",
                                        "sku": sku,
                                        "quantity": "1",
                                        "price": price[ship_code].amount,
                                        "currency": price[ship_code].currency
                                }]
                        }
                }]
        })
        if payment.create():
                for link in payment.links:
                        if link.rel == "approval_url":
                                paypal_approval_url = link.href 
        else:
                has_paypal_error = True

        return has_paypal_error, paypal_approval_url

在我的表格中:

    elif cd['payment_type'] == "2": # PayPal
                        is_paypal = True
                        has_paypal_error, paypal_approval_url = payPaypal(sku, price, ship_code)
                        payment_error_msg = _('Something went wrong, please try again')

thanks.html

if request.method == 'GET' and request.GET.get('paymentId'):
        paymentId = request.GET.get('paymentId')
        payment = paypalrestsdk.Payment.find(paymentId)
        payer_id = payment.payer.payer_info.payer_id

        if payment.execute({"payer_id": payer_id}):
                sendInvoiceEmailToUser(email_to_send_invoce, email_invoce_lang)
                sendSuccessNotificationToCrew(email_crew)
                return render(request, 'thanks.html')

查看响应情况" live",看起来像" approval_url"是对的:

[{'href': u'https://api.paypal.com/v1/payments/payment/PAY-######', 'method': u'GET', 'rel': u'self'}, 
{'href': u'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-####', 'method': u'REDIRECT', 'rel': u'approval_url'}, 
{'href': u'https://api.paypal.com/v1/payments/payment/PAY-####/execute', 'method': u'POST', 'rel': u'execute'}]

直播APP设置

my live settings in REST API

1 个答案:

答案 0 :(得分:1)

我发现了问题,它与PayPal无关。

我忘了从我的Django App中的settings.py中的ALLOWED_HOSTS中添加paypal域

ALLOWED_HOSTS = [ 'mysite.com.', '.paypal.com', 'paypal.com.' ]