Validation Error with start_date ISO 8601 Format in BillingAgreement

aimondo
Contributor
Contributor

Hi I am using the Paypal Python Rest SDK with python 2.7

 

this is how my billing agreement dictionary looks like:

 

ba_dict = {'description': u'Service: DE Run 800 -- Period of Service: 2017-07-08 -- 2017-08-08',
 'name': u'Service: DE Run 800 -- Period of Service: 2017-07-08 -- 2017-08-08',
 'payer': {u'payment_method': u'paypal'},
 'plan': {u'id': u'P-17U60867KM228661N5SIC4YI'},
 'shipping_address': {'city': u'Duesseldorf',
                      'country_code': u'DE',
                      'line1': u'Fleherstr. 32',
                      'line2': u'',
                      'phone': None,
                      'postal_code': u'40223',
                      'state': u'NRW'},
 'start_date': '2017-07-08T08:14:43.937609+00:00'}

 

after creating a billing agreement object with 

billing_agreement = BillingAgreement(ba_dict)

and this is the error code i am getting when i try billing_agreement.create()

{u'debug_id': u'63bceae5229ac',
u'details': [{u'field': u'start_date',
u'issue': u'Agreement start date is required, should be valid and greater than the current date. Should be consistent with ISO 8601 Format'}],
u'information_link': u'https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR',
u'message': u'Invalid request. See details.',
u'name': u'VALIDATION_ERROR'}

 

to me it looks like my start_date is iso 8601. I am using the datetime function of datetime.datetime.isoformat() to convert my datetime object into iso format. I just don't understand why billing agreement is throwing me a validation error

 

Login to Me Too
2 REPLIES 2

MTS_Ciaran
Moderator
Moderator

So the start_date should be in this format:

 

  "start_date": "2017-12-22T09:13:49Z",

 

Can you confirm that its actually the SDK thats setting it to the format you mentioned?

Login to Me Too

timmygee
New Community Member

To format the datetime value correctly in Python you need to do:

 

my_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')

This is taken from the PayPal SDK example here

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.