def verify_transaction(self, transaction: Transaction, data): url = "%s/bills/%s" % (self._server_url, transaction.id) headers = { "access-token": self.config["access_token"], "content-type": "application/json", } try: response = request("get", url, headers=headers) except RequestException: raise GatewayNetworkError("Cannot connect to bahamta server.") if response.status_code != 200: raise TransactionError("Invalid transaction information (%s)" % response.status_code) response_data = response.json() if response_data["state"] != "pay": raise TransactionError("Transaction not paid") if int(transaction.amount) != int(response_data["amount"]): raise TransactionError("Amount mismatch") transaction.pan = response_data["pay_pan"] transaction.meta = response_data return transaction
def verify_transaction(self, transaction: Transaction, data): try: params = { "terminalId": self.config["terminal_id"], "userName": self.config["username"], "userPassword": self.config["password"], "orderId": transaction.order_id, "saleOrderId": data["SaleOrderId"], "saleReferenceId": data["SaleReferenceId"], } client = Client(self._server_url) if "proxies" in self.config: client.transport.session.proxies = self.config["proxies"] result = client.service.bpVerifyRequest(**params) if int(result) != 0: client.service.bpReversalRequest(**params) raise TransactionError( "Mellat: invalid transaction, code: %s " % result ) result = client.service.bpSettleRequest(**params) if int(result) != 0: client.service.bpReversalRequest(**params) raise TransactionError( "Mellat: invalid transaction, code: %s " % result ) except zeep_exceptions.Error: raise GatewayNetworkError return transaction
def request_transaction(self, transaction: Transaction) -> Transaction: client = Client(self._server_url_request) if "proxies" in self.config: client.transport.session.proxies = self.config["proxies"] try: params = { "merchantId": self.config["merchant"], "invoiceNo": transaction.order_id, "paymentId": transaction.order_id, "specialPaymentId": transaction.order_id, "amount": int(transaction.amount), "description": "", "revertURL": self.config["callback_url"], } result = client.service.MakeToken(**params) token = result.token if token: transaction.id = token else: raise TransactionError("Irankish: invalid information.") except zeep_exceptions.Fault: raise TransactionError("Irankish: invalid information.") except zeep_exceptions.Error: raise GatewayNetworkError return transaction
def verify_transaction(self, transaction: Transaction, data): url = "https://pay.ir/pg/verify" formdata = { "api": "test" if self.testing else self.config["pin"], "token": transaction.id, } try: resp = request("post", url, data=formdata) except RequestException: raise GatewayNetworkError("Cannot connect to payir server") try: body = resp.json() except Exception: body = None if resp.status_code != 200: if not body: raise TransactionError( "Invalid transaction information (%s)" % resp.status_code ) raise TransactionError( "%s, code: %s" % (body["errorMessage"], body["errorCode"]) ) if int(transaction.amount) != int(body["amount"]): raise TransactionError("Amount mismatch") transaction.pan = body["cardNumber"] transaction.amount = int(body["amount"]) transaction.order_id = body["factorNumber"] transaction.meta = body return transaction
def verify_transaction(self, transaction: Transaction, data): try: parsed_data = self._parse_callback_data(data) params = { "merchantConfigurationID": int(self.config["merchant_config_id"]), "encryptedCredentials": self._encrypted_credentials, "payGateTranID": parsed_data["pay_gate_trans_id"], } client = Client(self._server_url) if "proxies" in self.config: client.transport.session.proxies = self.config["proxies"] verify_result = int(client.service.RequestVerification(**params)) if verify_result == 505: raise TransactionAlreadyPaidError( "AsanPardakht: transaction already verified") elif verify_result != 500: raise TransactionError( "AsanPardakht: invalid transaction, %s" % verify_result) reconcile_result = int( client.service.RequestReconciliation(**params)) if reconcile_result != 600: raise TransactionError( "AsanPardakht: invalid transaction settlement, %s" % reconcile_result) except zeep_exceptions.Error: raise GatewayNetworkError return transaction
def verify_transaction(self, transaction: Transaction, data): try: params = { "merchantId": self.config["merchant"], "referenceNumber": data["referenceId"] if "referenceId" in data else 0, "sha1Key": self.config["sha1key"], "token": transaction.id, } client = Client(self._server_url_verify) if "proxies" in self.config: client.transport.session.proxies = self.config["proxies"] result = int(client.service.KicccPaymentsVerification(**params)) if result > 0: if result != float(transaction.amount): raise TransactionError( "Irankish: invalid transaction, amount mismatch" ) elif result == -90: raise TransactionAlreadyPaidError( "Irankish: transaction already verified" ) else: raise TransactionError( "Irankish: invalid transaction, %s" % result ) except zeep_exceptions.Error: raise GatewayNetworkError return transaction
def request_transaction(self, transaction: Transaction) -> Transaction: client = Client(self._server_url) if "proxies" in self.config: client.transport.session.proxies = self.config["proxies"] try: params = { "merchantConfigurationID": self.config["merchant_config_id"], "encryptedRequest": self._get_encrypted_request(transaction), } result = client.service.RequestOperation(**params) if not result: raise TransactionError("AsanPardakht: invalid information.") if result[0:1] == "0": exploded_result = str(result).split( ",") # Should have two part [XX,YY] transaction.id = exploded_result[1] else: raise TransactionError( "AsanPardakht: invalid information. code: %s" % str(result)) except zeep_exceptions.Fault: raise TransactionError("AsanPardakht: invalid information.") except zeep_exceptions.Error: raise GatewayNetworkError return transaction
def verify_transaction(self, transaction: Transaction, data): formdata = { "pin": self.config["pin"], "amount": transaction.amount, "transid": transaction.id, } try: response = request( method="post", url="%s/verify" % self._server_url, data=formdata, ) except RequestException: raise GatewayNetworkError("Cannot connect to aqayepardakht server") if response.status_code != 200: raise TransactionError("Invalid transaction information (%s)" % response.status_code) if response.text == "2": raise TransactionAlreadyPaidError if response.text == "0": raise TransactionError("Transaction not paid") return transaction
def request_transaction(self, transaction: Transaction) -> Transaction: client = Client(self._server_url_request) if "proxies" in self.config: client.transport.session.proxies = self.config["proxies"] try: data = { "LoginAccount": self.config["pin"], "OrderId": transaction.order_id, "Amount": int(transaction.amount), "CallBackUrl": self.config["callback_url"], } result = client.service.SalePaymentRequest(requestData=data) token = result.Token status = int(result.Status) if token and status == 0: transaction.id = str(token) else: raise TransactionError( "Parsian: %s-%s" % (status, self._response_message_map[str(status)]) ) except zeep_exceptions.Fault: raise TransactionError("Parsian: invalid information.") except zeep_exceptions.Error: raise GatewayNetworkError return transaction
def request_transaction(self, transaction: Transaction) -> Transaction: data = { "payer_number": transaction.meta.get("payer_number"), "payer_name": transaction.meta.get("payer_name"), "amount": transaction.amount, "note": transaction.meta.get("note"), "silent": transaction.meta.get("silent"), } for key in ("payer_name", "payer_number", "note"): if data[key] is None: raise ValueError("Transaction meta required (%s)" % key) url = "%s/bills" % self._server_url headers = { "access-token": self.config["access_token"], "content-type": "application/json", } try: response = request("post", url, json=[data], headers=headers) except RequestException: raise GatewayNetworkError("Cannot connect to bahamta server.") if response.status_code != 200: raise TransactionError("Invalid transaction information (%s)" % response.status_code) response_data = response.json()[0] transaction.id = response_data["bill_id"] transaction.meta = response_data return transaction
def verify_transaction(self, transaction: Transaction, data): try: data = { "LoginAccount": self.config["pin"], "Token": transaction.id, } client = Client(self._server_url_verify) if "proxies" in self.config: client.transport.session.proxies = self.config["proxies"] result = client.service.ConfirmPayment(requestData=data) status = int(result.Status) if status == -1533: raise TransactionAlreadyPaidError( "Parsian: Transaction already paid" ) elif status != 0: raise TransactionError( "Parsian: %s-%s" % (status, self._response_message_map[str(status)]) ) except zeep_exceptions.Error: raise GatewayNetworkError transaction.pan = result.CardNumberMasked return transaction
def verify_transaction(self, transaction: Transaction, data): if data["id"] == "false": raise TransactionError("Invalid transaction ID") transaction.pan = data.get("cardNumber") print("Transaction verified: \n%s" % transaction.__repr__()) return transaction
def request_transaction(self, transaction: Transaction) -> Transaction: formdata = { "pin": self.config["pin"], "amount": irr_to_irt(transaction.amount), "callback": self.config["callback_url"], } optional_fields = ( "card_number", "invoice_id", "mobile", "description", ) for field in optional_fields: if field not in transaction.meta: continue formdata[field] = transaction.meta[field] try: response = request( method="post", url="%s/create" % self._server_url, data=formdata, ) except RequestException: raise GatewayNetworkError("Cannot connect to aqayepardakht server") if response.status_code != 200: raise TransactionError("Invalid transaction information (%s)" % response.status_code) transaction.id = response.text return transaction
def request_transaction(self, transaction: Transaction) -> Transaction: if int(transaction.amount) > self.maximum_amount: raise TransactionError("Amount is larger than %s" % self.maximum_amount) transaction.id = int(time.time()) print("New transaction requested: \n%s" % transaction.__repr__()) return transaction
def request_transaction(self, transaction: Transaction) -> Transaction: url = "https://pay.ir/pg/send" formdata = { "api": "test" if self.testing else self.config["pin"], "amount": transaction.amount, "redirect": self.config["callback_url"], } if transaction.order_id: formdata["factorNumber"] = transaction.order_id optional_fields = ( "mobile", "validCardNumber", "description", ) for field in optional_fields: if field not in transaction.meta: continue formdata[field] = transaction.meta[field] try: resp = request("post", url, data=formdata) except RequestException: raise GatewayNetworkError("Cannot connect to payir server") try: body = resp.json() except Exception: body = None if resp.status_code != 200: if not body: raise TransactionError( "Invalid transaction information (%s)" % resp.status_code ) raise TransactionError( "%s, code: %s" % (body["errorMessage"], body["errorCode"]) ) transaction.id = body["token"] return transaction
def request_transaction(self, transaction: Transaction) -> Transaction: client = Client(self._server_url) if "proxies" in self.config: client.transport.session.proxies = self.config["proxies"] try: params = { "terminalId": self.config["terminal_id"], "userName": self.config["username"], "userPassword": self.config["password"], "orderId": transaction.order_id, "amount": int(transaction.amount), "localDate": datetime.now().strftime("%Y%m%d"), "localTime": datetime.now().strftime("%H%M%S"), "additionalData": "", "callBackUrl": self.config["callback_url"], "payerId": 0, } result = client.service.bpPayRequest(**params) if not result: raise TransactionError( "Mellat: invalid information. %s" % result ) res = str(result).split(",") res_code = res[0] if int(res_code) == 0: transaction.id = res[1] else: raise TransactionError( "Mellat: invalid information. %s" % res_code ) except zeep_exceptions.Fault: raise TransactionError("Mellat: invalid information.") except zeep_exceptions.Error: raise GatewayNetworkError return transaction
def request_transaction(self, transaction: Transaction) -> Transaction: client = Client(self._server_url) try: result = client.service.PaymentRequest( self.config["merchant"], irr_to_irt(transaction.amount), self.config["description"], "", "", self.config["callback_url"], ) except zeep_exceptions.Fault: raise TransactionError("Zarinpal: invalid information") except zeep_exceptions.Error: raise GatewayNetworkError if result.Status == 100 and result.Authority: transaction.id = result.Authority else: raise TransactionError("Zarinpal: invalid information") return transaction
def verify_transaction(self, transaction: Transaction, data): try: client = Client(self._server_url) result = client.service.PaymentVerification( self.config["merchant"], transaction.id, irr_to_irt(transaction.amount), ) except zeep_exceptions.Error: raise GatewayNetworkError if result.Status == 100: return transaction elif result.Status == 101: raise TransactionAlreadyPaidError else: raise TransactionError("code: %s" % result.Status)