Esempio n. 1
1
class PayPalUI(QtGui.QDialog):
    def __init__(self):
        super(PayPalUI, self).__init__()
        self.ui = Ui_PaypalDialog()
        self.ui.setupUi(self)
        self.ui.happySlider.valueChanged.connect(self.ch_value)
        self.ui.happyButton.clicked.connect(self.create_payment)
        img = QtGui.QPixmap(get_file("paypal_logo.jpg"))
        self.ui.label_5.setPixmap(img)
        self.ui.label_5.setScaledContents(True)
        self.ui.label_5.setFixedSize(300, 50)
        self.ui.happyEdit.textChanged.connect(self.ch_text)
        self.ui.happyEdit.setText("3")
        self.ui.happyWebView.urlChanged.connect(self.ch_web_view)
        self.ui.happyWebView.loadProgress.connect(self.progress_webview)

    def progress_webview(self, progress):
        self.ui.progressBar.setValue(progress)

    def ch_value(self):
        self.ui.happyEdit.setText(str(self.ui.happySlider.value()))

    def ch_text(self):
        self.ui.happySlider.setValue(float(self.ui.happyEdit.text()))

    def ch_web_view(self):
        url = self.ui.happyWebView.url()
        url_string = url.toString()

        if "PayerID=" in url_string:
            for s in url_string.split("&"):
                if s.startswith("PayerID="):
                    id = s.strip("PayerID=")
                    if self.payment.execute({"payer_id": id}):
                        m_box_exec_success("Congratulations, you have made someone happy!")
                    else:
                        m_box_exec("Sorry, your transaction could not be completed.")

    def create_payment(self):
        price = self.ui.happyEdit.text()
        paypalrestsdk.configure(
            {
                "mode": "sandbox",  # sandbox or live
                "client_id": "ASS1fRDDkhHgMRXFYLJ9J02663eBb1ktC65nEQ6iVKbD4PyJPilbycGv6pxF",
                "client_secret": "EDo-XBCkEY72na40ngY_D6h8r6T2IhfBYtZoHEFV9Rf2sSYtsYDqmhexF3tO",
            }
        )
        self.payment = Payment(
            {
                "intent": "sale",
                # Payer
                # A resource representing a Payer that funds a payment
                # Payment Method as 'paypal'
                "payer": {"payment_method": "paypal"},
                # Redirect URLs
                "redirect_urls": {
                    "return_url": "http://roandigital.com/applications/synchronizerd/thanks",
                    "cancel_url": "http://roandigital.com/applications/synchronizerd/sorry",
                },
                # Transaction
                # A transaction defines the contract of a
                # payment - what is the payment for and who
                # is fulfilling it.
                "transactions": [
                    {
                        # ItemList
                        "item_list": {
                            "items": [
                                {"name": "SynchroniZeRD", "sku": "1", "price": price, "currency": "USD", "quantity": 1}
                            ]
                        },
                        # Amount
                        # Let's you specify a payment amount.
                        "amount": {"total": price, "currency": "USD"},
                        "description": "This is the payment transaction for SynchroniZeRD.",
                    }
                ],
            }
        )
        if self.payment.create():
            m_box_exec_success("Your payment was created, redirecting to paypal for authorization.")
            for link in self.payment.links:
                if link.method == "REDIRECT":
                    red = link.href
                    self.ui.happyWebView.load(red)
                    self.setMinimumSize(1024, 600)

        else:
            print("error")
Esempio n. 2
0
 def __init__(self):
     super(PayPalUI, self).__init__()
     self.ui = Ui_PaypalDialog()
     self.ui.setupUi(self)
     self.ui.happySlider.valueChanged.connect(self.ch_value)
     self.ui.happyButton.clicked.connect(self.create_payment)
     img = QtGui.QPixmap(get_file("paypal_logo.jpg"))
     self.ui.label_5.setPixmap(img)
     self.ui.label_5.setScaledContents(True)
     self.ui.label_5.setFixedSize(300, 50)
     self.ui.happyEdit.textChanged.connect(self.ch_text)
     self.ui.happyEdit.setText("3")
     self.ui.happyWebView.urlChanged.connect(self.ch_web_view)
     self.ui.happyWebView.loadProgress.connect(self.progress_webview)