Esempio n. 1
0
 def _do_create(self, profile_data):
     """
     Creates a new profile in the PayPal account with the specified id, using the specified data.
     """
     profile = WebProfile(profile_data)
     result = profile.create()
     if not result:
         raise CommandError("Could not create web profile: {}".format(profile.error))
     log.info("Created profile `%s` (id=%s).", profile.name, profile.id)
     return profile
Esempio n. 2
0
 def _do_create(self, profile_data):
     """
     Creates a new profile in the PayPal account with the specified id, using the specified data.
     """
     profile = WebProfile(profile_data)
     result = profile.create()
     if not result:
         raise CommandError("Could not create web profile: {}".format(profile.error))
     else:
         log.info("Created profile `%s` (id=%s).", profile.name, profile.id)
     return profile
Esempio n. 3
0
 def _do_update(self, profile_id, profile_data):
     """
     Updates the existing profile in the PayPal account with the specified id, replacing
     all data with the specified data.
     """
     profile = WebProfile.find(profile_id)
     result = profile.update(profile_data)
     if not result:
         raise CommandError("Could not update web profile: {}".format(profile.error))
     # have to re-fetch to show the new state
     profile = WebProfile.find(profile_id)
     log.info("Updated profile %s.", profile.id)
     return profile
Esempio n. 4
0
 def handle_show(self, options):
     """Wrapper for paypalrestsdk Find operation."""
     if not options.get('profile_id'):
         raise CommandError("Action `show` requires a profile_id to be specified.")
     profile_id = options.get('profile_id')
     profile = WebProfile.find(profile_id)
     self.print_json(profile.to_dict())
Esempio n. 5
0
    def handle_enable(self, args):
        """
        Given the id of an existing web profile, save a reference to it in the database.

        When PayPal checkouts are set up, we can look this profile up by name and, if
        found, specify its id in our API calls to customize the payment page accordingly.
        """
        profile_id = self._get_argument(args, 'profile_id', 'enable')
        profile = WebProfile.find(profile_id)
        self._do_enable(profile.id, profile.name)
Esempio n. 6
0
 def handle_list(self, args):  # pylint: disable=unused-argument
     """Wrapper for paypalrestsdk List operation."""
     profiles = WebProfile.all()
     result = []
     try:
         result = [profile.to_dict() for profile in profiles]
     except KeyError:
         # weird internal paypal sdk behavior; it means the result was empty.
         pass
     self.print_json(result)
 def _inverse_paypal_profile_info(self):
     paypal = self._get_paypal_api()
     for record in self:
         if not record.paypal_profile_info:
             continue
         info = json.loads(record.paypal_profile_info)
         if record.paypal_profile_id:
             web_profile = WebProfile.find(record.paypal_profile_id,
                                           api=paypal)
             if not web_profile.update(info):
                 raise UserError(
                     _("Error updating paypal profile:\n %s") %
                     web_profile.error)
         else:
             web_profile = WebProfile(info, api=paypal)
             if not web_profile.create():
                 raise UserError(
                     _("Error creating paypal profile:\n %s") %
                     web_profile.error)
             record.paypal_profile_id = web_profile.id
Esempio n. 8
0
    def handle_enable(self, options):
        """
        Given the id of an existing web profile, save a reference to it in the database.

        When PayPal checkouts are set up, we can look this profile up by name and, if
        found, specify its id in our API calls to customize the payment page accordingly.
        """
        if not options.get('profile_id'):
            raise CommandError("Action `enable` requires a profile_id to be specified.")
        profile_id = options.get('profile_id')
        profile = WebProfile.find(profile_id)
        self._do_enable(profile.id, profile.name)
Esempio n. 9
0
    def handle_delete(self, args):
        """
        Delete a web profile from the configured PayPal account.

        Before deleting this function checks to make sure a matching profile is not
        presently enabled.  If the specified profile is enabled the command will fail
        with an error, since leaving things in that state would cause the application
        to send invalid profile ids to PayPal, causing errors.
        """
        profile_id = self._get_argument(args, 'profile_id', 'delete')
        if PaypalWebProfile.objects.filter(id=profile_id).exists():
            raise CommandError(
                "Web profile {} is currently enabled.  You must disable it before you can delete it.".format(profile_id)
            )

        profile = WebProfile.find(profile_id)
        if not profile.delete():
            raise CommandError("Could not delete web profile: {}".format(profile.error))
        log.info("Deleted profile: %s", profile.id)
        self.print_json(profile.to_dict())
Esempio n. 10
0
 def handle_show(self, args):
     """Wrapper for paypalrestsdk Find operation."""
     profile_id = self._get_argument(args, 'profile_id', 'show')
     profile = WebProfile.find(profile_id)
     self.print_json(profile.to_dict())
Esempio n. 11
0
import string

logging.basicConfig(level=logging.INFO)

# Name needs to be unique so just generating a random one
wpn = ''.join(random.choice(string.ascii_uppercase) for i in range(12))

web_profile = WebProfile({
    "name": wpn,
    "presentation": {
        "brand_name": "YeowZa Paypal",
        "logo_image": "http://s3-ec.buzzfed.com/static/2014-07/18/8/enhanced/webdr02/anigif_enhanced-buzz-21087-1405685585-12.gif",
        "locale_code": "US"
    },
    "input_fields": {
        "allow_note": True,
        "no_shipping": 1,
        "address_override": 1
    },
    "flow_config": {
        "landing_page_type": "billing",
        "bank_txn_pending_url": "http://www.yeowza.com"
    }
})

if web_profile.create():
    print(("Web Profile[%s] created successfully" % (web_profile.id)))
else:
    print((web_profile.error))

payment = Payment({
import string

logging.basicConfig(level=logging.INFO)

# Name needs to be unique so just generating a random one
wpn = ''.join(random.choice(string.ascii_uppercase) for i in range(12))

web_profile = WebProfile({
    "name": wpn,
    "presentation": {
        "brand_name": "YeowZa Paypal",
        "logo_image": "http://s3-ec.buzzfed.com/static/2014-07/18/8/enhanced/webdr02/anigif_enhanced-buzz-21087-1405685585-12.gif",
        "locale_code": "US"
    },
    "input_fields": {
        "allow_note": True,
        "no_shipping": 1,
        "address_override": 1
    },
    "flow_config": {
        "landing_page_type": "billing",
        "bank_txn_pending_url": "http://www.yeowza.com"
    }
})

if web_profile.create():
    print("Web Profile[%s] created successfully"%(web_profile.id))
else:
    print(web_profile.error)

payment = Payment({
Esempio n. 13
0
from paypalrestsdk import WebProfile, ResourceNotFound
import logging

logging.basicConfig(level=logging.INFO)

try:
    web_profile = WebProfile.find("XP-3NWU-L5YK-X5EC-6KJM")
    print("Got Web Profile Details for Web Profile[%s]" % (web_profile.id))

    web_profile_update_attributes = [
        {
            "op": "replace",
            "path": "/presentation/brand_name",
            "value": "New Brand Name"
        }
    ]

    if web_profile.replace(web_profile_update_attributes):
        web_profile = WebProfile.find("XP-3NWU-L5YK-X5EC-6KJM")
        print("Web Profile [%s] name changed to [%s]" %
              (web_profile.id, web_profile.presentation.brand_name))
    else:
        print(web_profile.error)

except ResourceNotFound as error:
    print("Web Profile Not Found")
Esempio n. 14
0
from paypalrestsdk import WebProfile
import logging
logging.basicConfig(level=logging.INFO)

try:
    web_profile = WebProfile.find("XP-3NWU-L5YK-X5EC-6KJM")
    print(("Got Details for Web Profile[%s]" % (web_profile.id)))

except ResourceNotFound as error:
    print("Web Profile Not Found")
Esempio n. 15
0
from paypalrestsdk import WebProfile
import logging
logging.basicConfig(level=logging.INFO)

web_profile = WebProfile.find("XP-9R62-L4QJ-M8H6-UNV5")

if web_profile.delete():
    print("WebProfile deleted")
else:
    print(web_profile.error)
 def _compute_paypal_profile_info(self):
     paypal = self._get_paypal_api()
     for record in self.filtered(lambda a: a.paypal_profile_id):
         web_profile = WebProfile.find(record.paypal_profile_id, api=paypal)
         record.paypal_profile_info = json.dumps(web_profile.to_dict())
Esempio n. 17
0
from paypalrestsdk import WebProfile
import logging
logging.basicConfig(level=logging.INFO)

web_profile = WebProfile.find("XP-9R62-L4QJ-M8H6-UNV5")

if web_profile.delete():
  print("WebProfile deleted")
else:
  print(web_profile.error)
Esempio n. 18
0
from paypalrestsdk import WebProfile
import logging
logging.basicConfig(level=logging.INFO)

history = WebProfile.all()
print(history)

print("List WebProfile:")
for profile in history:
    print("  -> WebProfile[%s]" % (profile.name))