def send_ack(self, raw_tx, refund_addr):

        pay_det = self.payment_details
        if not pay_det.payment_url:
            return

        paymnt = paymentrequest_pb2.Payment()
        paymnt.merchant_data = pay_det.merchant_data
        paymnt.transactions.append(raw_tx)

        ref_out = paymnt.refund_to.add()
        ref_out.script = transaction.Transaction.pay_script(refund_addr)
        paymnt.memo = "Paid using Electrum"
        pm = paymnt.SerializeToString()

        payurl = urlparse.urlparse(pay_det.payment_url)
        try:
            r = requests.post(payurl.geturl(), data=pm, headers=ACK_HEADERS, verify=ca_path)
        except requests.exceptions.SSLError:
            print "Payment Message/PaymentACK verify Failed"
            try:
                r = requests.post(payurl.geturl(), data=pm, headers=ACK_HEADERS, verify=False)
            except Exception as e:
                print "Payment Message/PaymentACK Failed"
                print e
                return
        try:
            paymntack = paymentrequest_pb2.PaymentACK()
            paymntack.ParseFromString(r.content)
        except Exception:
            print "PaymentACK could not be processed. Payment was sent; please manually verify that payment was received."
            return

        print "PaymentACK message received: %s" % paymntack.memo
        return paymntack.memo
示例#2
0
 def send_ack(self, raw_tx, refund_addr):
     pay_det = self.details
     if not self.details.payment_url:
         return False, "no url"
     paymnt = pb2.Payment()
     paymnt.merchant_data = pay_det.merchant_data
     paymnt.transactions.append(bfh(raw_tx))
     ref_out = paymnt.refund_to.add()
     ref_out.script = util.bfh(util.pay_script(TYPE_ADDRESS, refund_addr))
     paymnt.memo = "Paid with the Bitcoin Payment Protocol Interface"
     pm = paymnt.SerializeToString()
     payurl = urllib.parse.urlparse(pay_det.payment_url)
     try:
         r = requests.post(payurl.geturl(),
                           data=pm,
                           headers=ACK_HEADERS,
                           verify=ca_path)
     except requests.exceptions.SSLError:
         print("Payment Message/PaymentACK verify Failed")
         try:
             r = requests.post(payurl.geturl(),
                               data=pm,
                               headers=ACK_HEADERS,
                               verify=False)
         except Exception as e:
             print(e)
             return False, "Payment Message/PaymentACK Failed"
     if r.status_code >= 500:
         return False, r.reason
     try:
         paymntack = pb2.PaymentACK()
         paymntack.ParseFromString(r.content)
     except Exception:
         return False, "PaymentACK could not be processed. Payment was sent; please manually verify that payment was received."
     return True, paymntack.memo
def payment_ack(serialized_payment_message: bytes,
                ) -> Tuple[bytes, Dict[str, str], CCoinAddress]:
    """Generates a PaymentACK object, captures client refund address
    and returns a tuple (message, refund_address)"""

    pao = o.PaymentACK()
    pao.payment.ParseFromString(serialized_payment_message)
    pao.memo = 'String shown to user after payment confirmation'

    refund_address = CCoinAddress.from_scriptPubKey(
        CScript(pao.payment.refund_to[0].script))

    sds_pa = pao.SerializeToString()

    headers = {'Content-Type': 'application/bitcoin-payment',
               'Accept': 'application/bitcoin-paymentack'}

    return sds_pa, headers, refund_address