def paypal_payment_history(**kwargs): query_param = { 'count': 100, 'sort_by': 'create_time', 'sort_order': 'desc', 'start_time': kwargs['start_time'], 'end_time': kwargs['end_time'] } if kwargs.get('start_id'): query_param['start_id'] = kwargs['start_id'] payment_history = Payment.all(query_param) return payment_history
# #GetPaymentList Sample # This sample code demonstrate how you can # retrieve a list of all Payment resources # you've created using the Payments API. # Note various query parameters that you can # use to filter, and paginate through the # payments list. # API used: GET /v1/payments/payments from paypalrestsdk import Payment import logging logging.basicConfig(level=logging.INFO) # ###Retrieve # Retrieve the PaymentHistory by calling the # `all` method # on the Payment class # Refer the API documentation # for valid values for keys # Supported paramters are :count, :next_id payment_history = Payment.all({"count": 2}) # List Payments print("List Payment:") for payment in payment_history.payments: print(" -> Payment[%s]"%(payment.id))
# GetPaymentList Sample # This sample code demonstrate how you can # retrieve a list of all Payment resources # you've created using the Payments API. # Note various query parameters that you can # use to filter, and paginate through the # payments list. # API used: GET /v1/payments/payments from paypalrestsdk import Payment import logging logging.basicConfig(level=logging.INFO) # Retrieve # Retrieve the PaymentHistory by calling the # `all` method # on the Payment class # Refer the API documentation # for valid values for keys # Supported paramters are :count, :next_id payment_history = Payment.all({"count": 2}) # List Payments print("List Payment:") for payment in payment_history.payments: print(" -> Payment[%s]" % (payment.id))
def get_payments(self, count = 10): payment_history = Payment.all({"count": count}).payments return payment_history
def get_payments_since(next_id=None, conn=None): if next_id is None: start_time = get_start_time(conn) payment_history = Payment.all({"count": 20, "start_time": start_time}) else: payment_history = Payment.all({"count": 20, "start_id": next_id}) """ p1 = payment_history.to_dict() p2 = ph2.to_dict() print([p1['next_id'], p2['next_id']]) print(p1['payments'][0]['create_time']) print(p1['payments'][19]['create_time']) print(p2['payments'][0]['create_time']) print(p2['payments'][19]['create_time']) """ rows = [] for payment in payment_history.payments: p = payment.to_dict() id = p['id'] intent = p['intent'] state = p['state'] create_time = p['create_time'] payment_method = p['payer']['payment_method'] payer_status = p['payer']['status'] phone = p['payer']['payer_info']['phone'] first_name = p['payer']['payer_info']['first_name'] email = p['payer']['payer_info']['email'] country = p['payer']['payer_info']['country_code'] lastname = p['payer']['payer_info']['last_name'] payer_id = p['payer']['payer_info']['payer_id'] sa = p['payer']['payer_info']['shipping_address'] address_line1 = sa['line1'] shipping_name = sa['recipient_name'] shipping_city = sa['city'] shipping_postal_code = sa['postal_code'] shipping_state = sa['state'] shipping_country = sa['country_code'] num_transactions = len(p['transactions']) t = p['transactions'][0] desc = t['description'] total = float(t['amount']['total']) currency = t['amount']['currency'] fee = float( t['related_resources'][0]['sale']['transaction_fee']['value']) row = { "id": id, "intent": intent, "state": state, "create_time": create_time, "payment_method": payment_method, "payer_status": payer_status, "phone": phone, "first_name": first_name, "email": email, "country": country, "lastname": lastname, "payer_id": payer_id, "address_line1": address_line1, "shipping_name": shipping_name, "shipping_city": shipping_city, "shipping_postal_code": shipping_postal_code, "shipping_state": shipping_state, "shipping_country": shipping_country, "num_transactions": num_transactions, "desc": desc, "total": total, "currency": currency, "fee": fee } rows.append(row) if len(rows): return None df = pd.DataFrame(rows) try: next_id = payment_history['next_id'] except KeyError: next_id = None return df, next_id