High VoltagesAsim Zulfiqar
Published

Integrate PayPal in Your Raspberry Pi Projects

This tutorial will help you integrate a payment solution into your Raspberry Pi project using webhooks and MQTT.

AdvancedProtip2 hours623
Integrate PayPal in Your Raspberry Pi Projects

Things used in this project

Story

Read more

Code

Python code

Python
# Import all the libraries
from pubnub import Pubnub
import time
# Initialize the Pubnub Keys
# Replace them with your keysets
pub_key = "pub-c-XXXXXXXXXXXXX"
sub_key = "sub-c-XXXXXXXXXXXXX"
def init():  
    # initalize the pubnub keys and start subscribing
    global pubnub
    # Pubnub Initialization
    pubnub = Pubnub(publish_key=pub_key, subscribe_key=sub_key)
    pubnub.subscribe(channels='paymentTrigger', callback=callback, error=callback, reconnect=reconnect,disconnect=disconnect)

def get_message(controlCommand):
     if (controlCommand.has_key("trigger")):
        if (controlCommand["trigger"] == "anything" and controlCommand["status"] == 1):
            print("payment recieved")
        else:
            pass
    else:
        pass
def callback(message, channel):
  
    print(message)
    if (message.has_key("requester")):
        get_message(message)
    else:
        passdef error(message):
  # if there is error in the channel,print the  error
    print("ERROR : " + str(message))
def reconnect(message):
  # responds if server connects with pubnub
    print("RECONNECTED")
def disconnect(message):
  # responds if server disconnects with pubnub
    print("DISCONNECTED")
if __name__ == '__main__':
    init()  # Initialize the Script

Credits

High Voltages

High Voltages

12 projects • 49 followers
High Voltages is all about electronics and computer engineering. We are skilled in the embedded system, IoT, Python, and circuit design.
Asim Zulfiqar

Asim Zulfiqar

11 projects • 28 followers

Comments