def result(request):
    context = dict()

    current_user = request.user
    order = Order.objects.filter(user__id=current_user.id).last()

    url = request.META.get('index')

    request = {
        'locale': 'tr',
        'conversationId': str(order.code),
        'token': sozlukToken[0]
    }
    checkout_form_result = iyzipay.CheckoutForm().retrieve(request, options)
    result = checkout_form_result.read().decode('utf-8')
    sonuc = json.loads(result, object_pairs_hook=list)

    if sonuc[0][1] == 'success':
        context['success'] = 'Başarılı İŞLEMLER'
        return HttpResponseRedirect(reverse('success'), context)

    elif sonuc[0][1] == 'failure':
        context['failure'] = 'Başarısız'
        return HttpResponseRedirect(reverse('failure'), context)

    return HttpResponse(url)
Esempio n. 2
0
def result(request):
    context = dict()

    url = request.META.get('order_index')
    print("result içindeki token -----", sozlukToken)
    request = {
        'locale': 'tr',
        'conversationId': '123456789',
        'token': sozlukToken[0]
    }
    checkout_form_result = iyzipay.CheckoutForm().retrieve(request, options)
    print("************************")
    print(type(checkout_form_result))
    result = checkout_form_result.read().decode('utf-8')
    print("************************")
    print(sozlukToken[0])   # Form oluşturulduğunda
    print("************************")
    sonuc = json.loads(result, object_pairs_hook=list)
    #print(sonuc[0][1])  # İşlem sonuç Durumu dönüyor
    #print(sonuc[5][1])   # Test ödeme tutarı
    print("************************")
    for i in sonuc:
        print(i)
    print("************************")
    if sonuc[0][1] == 'success':
        context['success'] = 'Başarılı İŞLEMLER'
        return HttpResponseRedirect(reverse('success'), context)

    elif sonuc[0][1] == 'failure':
        context['failure'] = 'Başarısız'
        return HttpResponseRedirect(reverse('failure'), context)

    return HttpResponse(url)
Esempio n. 3
0
 def get_retrive_data(self, data: dict) -> dict:
     try:
         data.update({'locale': self._context.get('lang').split('_')[0]})
         checkout_form_retrieve = iyzipay.CheckoutForm()
         retrieve_data = checkout_form_retrieve.retrieve(
             data, self._get_option_dict())
         response = ast.literal_eval(retrieve_data.read().decode('utf-8'))
     except Exception as e:
         raise UserError(e)
     return response
Esempio n. 4
0
def payment_result(request):

    request_iyzico = dict([('locale', 'tr')])
    # request['conversationId'] = '123456789'
    request_iyzico['token'] = request.POST.get("token")

    checkout_form_auth = iyzipay.CheckoutForm()
    checkout_form_auth_response = checkout_form_auth.retrieve(
        request_iyzico, settings.IYZICO_OPTIONS)
    status_content = checkout_form_auth_response.read().decode('utf-8')
    status_content = json.loads(status_content)
    print(status_content)
    context = {'content': status_content}
    return render(request, 'payment_result.html', context)
Esempio n. 5
0
def success(request):
    print(request.POST)
    token = request.POST.get('token')

    options = {
        'api_key': settings.IYZIPAY_API_KEY,
        'secret_key': settings.IYZIPAY_API_SECRET,
        'base_url': settings.IYZIPAY_API_BASE_URL
    }

    data = {
        'locale': 'tr',
        'token': token
    }

    checkout_form_result = iyzipay.CheckoutForm().retrieve(data, options)

    response = json.loads(checkout_form_result.read().decode('utf-8'))
    return JsonResponse(data=response)
Esempio n. 6
0
def odeme_sonuc_iyzico(request):
    x = request
    iyzico = PaymentMethodIyzico.objects.get(payment_type__name='Iyzico')
    order_token = IyzicoToken.objects.get(token=x.POST.get('token')).order_id
    request = dict([('locale', 'tr')])
    request['conversationId'] = str(order_token.id)
    request['token'] = x.POST.get('token')
    order = Order.objects.get(pk=int(request['conversationId']))

    options = {
        'api_key': iyzico.apiKey,
        'secret_key': iyzico.secretKey,
        'base_url': iyzipay.base_url,
    }

    checkout_form_result = iyzipay.CheckoutForm().retrieve(request, options)
    status = json.loads(checkout_form_result.read())['status']

    if status == "success":  ## Ödeme Onaylandı
        order.isPayed = True
        orderProducts = OrderProduct.objects.filter(order=order)
        for orderProduct in orderProducts:
            product = Product.objects.get(pk=orderProduct.product.pk)
            product.stock = product.stock - orderProduct.quantity
            product.save()
        order.order_situations.add(
            OrderSituations.objects.get(name="Onay Bekliyor"))
        order.save()

    else:
        order.delete()

    response = HttpResponse()
    response.write("OK")

    return render(request, "odeme/odeme-bildirim.html", {"odeme": "OK"})
import iyzipay

options = {
    'api_key': iyzipay.api_key,
    'secret_key': iyzipay.secret_key,
    'base_url': iyzipay.base_url
}

request = {'locale': 'tr', 'conversationId': '123456789', 'token': 'token'}

checkout_form_result = iyzipay.CheckoutForm().retrieve(request, options)

print(checkout_form_result.read().decode('utf-8'))