def ode(): payment = iyzipay.Payment().create(request, options) ode = payment.read().decode('utf-8') dic = json.loads(ode) print(dic) return dic["status"]
def retrieve_payment_result(request): options = { 'api_key': settings.IYZIPAY_API_KEY, 'secret_key': settings.IYZIPAY_API_SECRET, 'base_url': settings.IYZIPAY_API_BASE_URL } data = { 'locale': 'tr', 'paymentId': '12277814', } payment = iyzipay.Payment().retrieve(data, options) response = json.loads(payment.read().decode('utf-8')) return JsonResponse(data=response)
'price': '0.5' }, { 'id': 'BI103', 'name': 'Usb', 'category1': 'Electronics', 'category2': 'Usb / Cable', 'itemType': 'PHYSICAL', 'price': '0.2' }] request = { 'locale': 'tr', 'conversationId': '123456789', 'price': '1', 'paidPrice': '1.2', 'currency': 'TRY', 'installment': '1', 'basketId': 'B67832', 'paymentChannel': 'WEB', 'paymentGroup': 'PRODUCT', 'paymentCard': payment_card, 'buyer': buyer, 'shippingAddress': address, 'billingAddress': address, 'basketItems': basket_items } payment = iyzipay.Payment().create(request, options) print(payment.body)
def payment_with_api_with_saved_payment_card(request): payment_card = UserPaymentCard.objects.last() options = { 'api_key': settings.IYZIPAY_API_KEY, 'secret_key': settings.IYZIPAY_API_SECRET, 'base_url': settings.IYZIPAY_API_BASE_URL } payment_card = { 'cardUserKey': payment_card.card_user_key, 'cardToken': payment_card.card_token } buyer = { 'id': 'BY789', 'name': 'John', 'surname': 'Doe', 'gsmNumber': '+905350000000', 'email': '*****@*****.**', 'identityNumber': '74300864791', 'lastLoginDate': '2015-10-05 12:43:35', 'registrationDate': '2013-04-21 15:12:09', 'registrationAddress': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', 'ip': '85.34.78.112', 'city': 'Istanbul', 'country': 'Turkey', 'zipCode': '34732' } address = { 'contactName': 'Jane Doe', 'city': 'Istanbul', 'country': 'Turkey', 'address': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', 'zipCode': '34732' } basket_items = [ { 'id': 'BI102', 'name': 'Game code', 'category1': 'Game', 'category2': 'Online Game Items', 'itemType': 'VIRTUAL', 'price': '60' } ] data = { 'locale': 'tr', 'conversationId': '123456789', 'price': '60', 'paidPrice': '60', 'currency': 'TRY', 'installment': '1', 'basketId': 'B67832', 'paymentChannel': 'WEB', 'paymentGroup': 'PRODUCT', 'paymentCard': payment_card, 'buyer': buyer, 'shippingAddress': address, 'billingAddress': address, 'basketItems': basket_items } payment = iyzipay.Payment().create(data, options) response = json.loads(payment.read().decode('utf-8')) return JsonResponse(data=response)
def payment_with_api(request): """ 3D security olmadan iyzico endpointi üzerinden api kullanılarak satın alınma işleminde, callback url'e gerek duyulmuyor. Eğer registerCard : 1 olarak işaretlenirse kartın kaydelieceğini ve dönüşte kayıtl bilgilerini dönderecektir. :param request: :return: """ options = { 'api_key': settings.IYZIPAY_API_KEY, 'secret_key': settings.IYZIPAY_API_SECRET, 'base_url': settings.IYZIPAY_API_BASE_URL } payment_card = { 'cardHolderName': 'John Doe', 'cardNumber': '5528790000000008', 'expireMonth': '12', 'expireYear': '2030', 'cvc': '123', 'registerCard': '0' } buyer = { 'id': 'BY789', 'name': 'John', 'surname': 'Doe', 'gsmNumber': '+905350000000', 'email': '*****@*****.**', 'identityNumber': '74300864791', 'lastLoginDate': '2015-10-05 12:43:35', 'registrationDate': '2013-04-21 15:12:09', 'registrationAddress': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', 'ip': '85.34.78.112', 'city': 'Istanbul', 'country': 'Turkey', 'zipCode': '34732' } address = { 'contactName': 'Jane Doe', 'city': 'Istanbul', 'country': 'Turkey', 'address': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', 'zipCode': '34732' } basket_items = [ { 'id': 'BI101', 'name': 'Binocular', 'category1': 'Collectibles', 'category2': 'Accessories', 'itemType': 'PHYSICAL', 'price': '10' } ] data = { 'locale': 'tr', 'conversationId': '123456789', 'price': '10', 'paidPrice': '12', 'currency': 'TRY', 'installment': '1', 'basketId': 'B67832', 'paymentChannel': 'WEB', 'paymentGroup': 'PRODUCT', 'paymentCard': payment_card, 'buyer': buyer, 'shippingAddress': address, 'billingAddress': address, 'basketItems': basket_items } payment = iyzipay.Payment().create(data, options) response = json.loads(payment.read().decode('utf-8')) return JsonResponse(data=response)
import iyzipay options = { 'api_key': iyzipay.api_key, 'secret_key': iyzipay.secret_key, 'base_url': iyzipay.base_url } request = { 'locale': 'tr', 'conversationId': '123456789', 'paymentId': '1', 'paymentConversationId': '123456789' } payment = iyzipay.Payment().retrieve(request, options) print(payment.read().decode('utf-8'))
def pay(request): form = PayForm(request.POST or None) context = {"form": form} if form.is_valid(): print(form.cleaned_data) ad = form.cleaned_data.get("ad") soyad = form.cleaned_data.get("soyad") kart_no = form.cleaned_data.get("kart_no") ay = form.cleaned_data.get("ay") yil = form.cleaned_data.get("yil") cvc = form.cleaned_data.get("cvc") tel_no = form.cleaned_data.get("tel_no") email = form.cleaned_data.get("email") adres = form.cleaned_data.get("adres") sehir = form.cleaned_data.get("sehir") ulke = form.cleaned_data.get("ulke") para = form.cleaned_data.get("para") options = { 'api_key': "sandbox-xMmsty6A68us9iGfhLxIm7UVQ4WRSlQy", 'secret_key': "sandbox-QQnp3eC4j2kYe5nCS0nogK4H0gCau9HH", 'base_url': iyzipay.base_url } kart = { 'cardHolderName': ad + " " + soyad, 'cardNumber': kart_no, 'expireMonth': ay, 'expireYear': yil, 'cvc': cvc, 'registerCard': '0' } alici = { 'id': 'BY789', 'name': ad, 'surname': soyad, 'gsmNumber': tel_no, 'email': email, 'identityNumber': '74300864791', 'lastLoginDate': '2015-10-05 12:43:35', 'registrationDate': '2013-04-21 15:12:09', 'registrationAddress': adres, 'ip': '85.34.78.112', 'city': sehir, 'country': ulke, 'zipCode': '34732' } adres = { 'contactName': ad + " " + soyad, 'city': sehir, 'country': ulke, 'address': adres, 'zipCode': '34732' } sepet = [{ 'id': 'BI101', 'name': 'Kalem', 'category1': 'Kırtasiye', 'category2': 'Ofis', 'itemType': 'PHYSICAL', 'price': para }] istek = { 'locale': 'tr', 'conversationId': '123456789', 'price': para, 'paidPrice': para, 'currency': 'TRY', 'installment': '1', 'basketId': 'B67832', 'paymentChannel': 'WEB', 'paymentGroup': 'PRODUCT', 'paymentCard': kart, 'buyer': alici, 'shippingAddress': adres, 'billingAddress': adres, 'basketItems': sepet } payment_card = kart buyer = alici address = adres basket_items = sepet request = istek payment = iyzipay.Payment().create(request, options) ode = payment.read().decode('utf-8') dic = json.loads(ode) print(dic) if dic["status"] == "success": form.save() return redirect("detail") return render(request, "pay.html", context)
def payment_form(request): try: cart = Cart.objects.get(id=request.session.get('cart')) except Cart.DoesNotExist: cart = Cart.objects.create() request.session['cart'] = cart.id cart_items = CartItem.objects.filter(cart=cart, ) cart_issues = CartIssue.objects.filter(cart=cart, ) # FIXME: price_total = sum([item.price for item in cart.items.all()]) if request.method == 'POST': form = PaymentForm(request.POST) if form.is_valid(): payment_card = { 'cardHolderName': form.cleaned_data['card_holder_name'], 'cardNumber': form.cleaned_data['card_number'], 'expireMonth': form.cleaned_data['expiry_month'], 'expireYear': form.cleaned_data['expiry_year'], 'cvc': form.cleaned_data['cvc'], } order = form.save() buyer = { 'id': str(order.id), 'name': ' '.join(order.name.split()[:-1]), 'surname': order.name.split()[-1], 'gsmNumber': order.gsm_number, 'email': order.email, 'identityNumber': order.identity_number, 'registrationAddress': order.address, 'ip': request.META.get('HTTP_X_FORWARDED_FOR', request.META.get('REMOTE_ADDR', '')).split(',')[0].strip(), 'city': order.city, 'country': order.country, 'zipCode': order.zipcode, } address = { 'contactName': order.name, 'city': order.city, 'country': order.country, 'address': order.address, 'zipCode': order.zipcode, } basket_items = [ { 'id': '12345', 'name': 'Gazete', 'category1': 'Gazete', # 'category2': 'Accessories', 'itemType': 'PHYSICAL', 'price': '1' }, ] req = { 'locale': 'tr', 'conversationId': str(order.id), 'price': price_total, 'paidPrice': price_total, 'currency': 'TRY', 'installment': '1', 'paymentGroup': 'PRODUCT', # PRODUCT, LISTING, SUBSCRIPTION, OTHER 'paymentCard': payment_card, 'buyer': buyer, 'shippingAddress': address, 'billingAddress': address, 'basketItems': basket_items, } if form.cleaned_data['secure3d']: req.update({ 'callbackUrl': '%s%s' % (settings.SITE_BASE_URL, reverse('shop_3ds_callback')), }) three_d_s_initialize = iyzipay.ThreedsInitialize() r = three_d_s_initialize.create(req, API_PARAMS) if r.status == 200: response = json.loads(r.read()) if response['status'] == 'success': print(response['threeDSHtmlContent']) return render( request, 'shop/3ds_form.html', { '3ds_bank_form': b64decode(response['threeDSHtmlContent']). decode('utf-8'), }) else: payment = iyzipay.Payment().create(req, API_PARAMS) else: form = PaymentForm() return render(request, 'shop/payment_form.html', { 'form': form, 'cart': cart, 'price_total': price_total, })
def pay(request): response_data = {} if request.method == 'POST': try: ip_address = get_client_ip(request) name = request.POST.get("name") surname = request.POST.get("surname") email = request.POST.get("email") country = request.POST.get("country") city = request.POST.get("city") full_address = request.POST.get("full_address") credit_amount = request.POST.get("credit_amount") card_name = request.POST.get("card_name") card_number = request.POST.get("card_number").replace(" ", "") card_number = str(card_number) expiration_date = request.POST.get("expiration_date") expiration_date = expiration_date.split("/") expiration_month = expiration_date[0] expiration_year = expiration_date[1] security_code = request.POST.get("security_code") payment_card = { 'cardHolderName': card_name, 'cardNumber': card_number, 'expireMonth': expiration_month, 'expireYear': '20' + expiration_year, 'cvc': security_code, 'registerCard': '0' } buyer = { 'id': 'BY789', 'name': name, 'surname': surname, # 'gsmNumber': '+905350000000', 'email': email, 'identityNumber': '74300864791', # 'lastLoginDate': '2015-10-05 12:43:35', # 'registrationDate': '2013-04-21 15:12:09', 'registrationAddress': full_address, 'ip': ip_address, 'city': city, 'country': country, # 'zipCode': '34732' } address = { 'contactName': name + ' ' + surname, 'city': city, 'country': country, 'address': full_address, } # default value for request basket_items = [{ 'id': '1', 'name': 'KrediEkleme', 'category1': 'Kredi', 'itemType': 'VIRTUAL', 'price': '1' }] request_iyzico = { 'locale': 'tr', 'conversationId': '123456789', 'price': '1', 'paidPrice': credit_amount, 'currency': 'TRY', 'installment': '1', 'basketId': 'B67832', 'paymentChannel': 'WEB', 'paymentGroup': 'PRODUCT', 'paymentCard': payment_card, 'buyer': buyer, 'shippingAddress': address, 'billingAddress': address, 'basketItems': basket_items } payment = iyzipay.Payment().create(request_iyzico, settings.IYZICO_OPTIONS) status_content = str(payment.read().decode('utf-8')) # TODO: Log here status_content = json.loads(status_content) if status_content["status"] == "failure": raise Error('this process cannot be valid. Error = {}'.format( status_content["errorMessage"])) except Error as e: # TODO: Log here response_data['error'] = True response_data['result'] = e.args[0] return HttpResponse(json.dumps(response_data), content_type="application/json") else: context = { 'test': 'test', 'page_info_title': _('Payment'), } return render(request, 'base.html', context)