rpip / paystack-go

Go library for the Paystack API https://developers.paystack.co/v1.0/reference
MIT License
63 stars 42 forks source link

No Default UA Sent With Requests #2

Open steveamaza opened 6 years ago

steveamaza commented 6 years ago

Sometimes, Cloudflare blocks API requests sent to Paystack servers that have no accompanying User Agent. Setting API requests with any User Agent resolves this.

My favourite UA is Chrome's (for no reason 😀 ) Mozilla/5.0 (Unknown; Linux) AppleWebKit/538.1 (KHTML, like Gecko) Chrome/v1.0.0 Safari/538.1

Ajibola commented 6 years ago

@steveamaza could that be the reason for this error

{ "code": 400, "details": {}, "url": { "Scheme": "https", "Opaque": "", "User": null, "Host": "api.paystack.co", "Path": "/charge", "RawPath": "", "ForceQuery": false, "RawQuery": "", "Fragment": "" }, "header": { "Access-Control-Allow-Origin": [ "*" ], "Cf-Ray": [ "4130f86afd762993-DUB" ], "Content-Length": [ "80" ], "Content-Type": [ "application/json; charset=utf-8" ], "Date": [ "Sun, 29 Apr 2018 10:08:58 GMT" ], "Etag": [ "W/\"50-1OmteF9EHlts1wNCZyvxIA\"" ], "Expect-Ct": [ "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\"" ], "Server": [ "cloudflare" ], "Set-Cookie": [ "__cfduid=de2207b3a95cbc631af2eb860d36289131524996538; expires=Mon, 29-Apr-19 10:08:58 GMT; path=/; domain=.paystack.co; HttpOnly", "sails.sid=s%3A8C9sZpbqB2Csy6aMU41LhyapUfL5tNiU.eDQAaIkJfXqA6PbmC4OVhcgGiC2tjC6ALZ9NhpEpx%2FM; Path=/; HttpOnly; Secure" ], "Strict-Transport-Security": [ "max-age=15552000; includeSubDomains; preload" ], "Vary": [ "X-HTTP-Method-Override" ], "X-Content-Type-Options": [ "nosniff" ], "X-Powered-By": [ "Sails " ] } }

steveamaza commented 6 years ago

I believe so

On Sun, 29 Apr 2018, 11:12 Ajibola, notifications@github.com wrote:

@steveamaza https://github.com/steveamaza could that be the reason for this error

{ "code": 400, "details": {}, "url": { "Scheme": "https", "Opaque": "", "User": null, "Host": "api.paystack.co", "Path": "/charge", "RawPath": "", "ForceQuery": false, "RawQuery": "", "Fragment": "" }, "header": { "Access-Control-Allow-Origin": [ "*" ], "Cf-Ray": [ "4130f86afd762993-DUB" ], "Content-Length": [ "80" ], "Content-Type": [ "application/json; charset=utf-8" ], "Date": [ "Sun, 29 Apr 2018 10:08:58 GMT" ], "Etag": [ "W/"50-1OmteF9EHlts1wNCZyvxIA"" ], "Expect-Ct": [ "max-age=604800, report-uri=" https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"" ], "Server": [ "cloudflare" ], "Set-Cookie": [ "__cfduid=de2207b3a95cbc631af2eb860d36289131524996538; expires=Mon, 29-Apr-19 10:08:58 GMT; path=/; domain=.paystack.co; HttpOnly", "sails.sid=s%3A8C9sZpbqB2Csy6aMU41LhyapUfL5tNiU.eDQAaIkJfXqA6PbmC4OVhcgGiC2tjC6ALZ9NhpEpx%2FM; Path=/; HttpOnly; Secure" ], "Strict-Transport-Security": [ "max-age=15552000; includeSubDomains; preload" ], "Vary": [ "X-HTTP-Method-Override" ], "X-Content-Type-Options": [ "nosniff" ], "X-Powered-By": [ "Sails " ] } }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/rpip/paystack-go/issues/2#issuecomment-385240607, or mute the thread https://github.com/notifications/unsubscribe-auth/APG0O-doBvDPxjZz-Cx6-ACCZkofFlNaks5ttZIrgaJpZM4Tfrgv .

rpip commented 6 years ago

Hey guys! Sorry for the late response to this.

UA config was in the code but noticed there was a gap in the logic in how the UA was set. The idea was to allow devs to append custom UAs to the code to further identify where the request is coming from. I have simplified it now so UA is always to set to something like paystack-go/$CURRENT_LIB_VERSION. See https://github.com/rpip/paystack-go/blob/master/paystack.go#L29

rpip commented 6 years ago

Ah the build failed:

{
  "code": 400,
  "details": null,
  "url": {
    "Scheme": "https",
    "Opaque": "",
    "User": null,
    "Host": "api.paystack.co",
    "Path": "/transferrecipient",
    "RawPath": "",
    "ForceQuery": false,
    "RawQuery": "",
    "Fragment": ""
  },
  "header": {
    "Access-Control-Allow-Origin": [
      "*"
    ],
    "Cf-Ray": [
      "4183a89d4fe923c6-IAD"
    ],
    "Content-Length": [
      "63"
    ],
    "Content-Type": [
      "application/json; charset=utf-8"
    ],
    "Date": [
      "Wed, 09 May 2018 10:59:47 GMT"
    ],
    "Etag": [
      "W/\"3f-jtwy0qN2ikmb7AbT8QWXag\""
    ],
    "Expect-Ct": [
      "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
    ],
    "Server": [
      "cloudflare"
    ],
    "Set-Cookie": [
      "__cfduid=d378bf28bb40ed403c192fecc043a84e61525863587; expires=Thu, 09-May-19 10:59:47 GMT; path=/; domain=.paystack.co; HttpOnly",
      "sails.sid=s%3AmIH2M2O82TP5W2IvttZLpTXcH68MTljj.fQ%2FsbFnYV3SoVz45zs8lm%2BXY58SHWMkaaMCowZ90QoI; Path=/; HttpOnly; Secure"
    ],
    "Strict-Transport-Security": [
      "max-age=15552000; includeSubDomains; preload"
    ],
    "Vary": [
      "X-HTTP-Method-Override"
    ],
    "X-Content-Type-Options": [
      "nosniff"
    ],
    "X-Powered-By": [
      "Sails <sailsjs.org>"
    ]
  }
}
rpip commented 6 years ago

Updated the UA to use the Mozilla UA @steveamaza suggested, but the build is still failing.

Won't be able to look into this again anytime soon. Happy to give access to anyone interested in helping maintain the lib. Thanks!

rpip commented 6 years ago

Hi @steveamaza, actually, it's the transfer test that's failing. The error response from Paystack doesn't indicate why.

TestTransferRecipientList (0.96s) transfer_test.go:95:


{
  "code": 400,
  "details": null,
  "url": {
    "Scheme": "https",
    "Opaque": "",
    "User": null,
    "Host": "api.paystack.co",
    "Path": "/transferrecipient",
    "RawPath": "",
    "ForceQuery": false,
    "RawQuery": "",
    "Fragment": ""
  },
  "header": {
    "Access-Control-Allow-Origin": [
      "*"
    ],
    "Cf-Ray": [
      "4183c08a5d57244a-IAD"
    ],
    "Content-Length": [
      "63"
    ],
    "Content-Type": [
      "application/json; charset=utf-8"
    ],
    "Date": [
      "Wed, 09 May 2018 11:16:07 GMT"
    ],
    "Etag": [
      "W/\"3f-jtwy0qN2ikmb7AbT8QWXag\""
    ],
    "Expect-Ct": [
      "max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""
    ],
    "Server": [
      "cloudflare"
    ],
    "Set-Cookie": [
      "__cfduid=dcbd3d400b01a7db18990bdd903108dd61525864567; expires=Thu, 09-May-19 11:16:07 GMT; path=/; domain=.paystack.co; HttpOnly",
      "sails.sid=s%3AUwZPOMIqNpoQM08VaquhUW16M-xauiGA.wLPqT0Vs2naRzrhfGiWj8G80z%2B5hySsvadfFJcNoJQo; Path=/; HttpOnly; Secure"
    ],
    "Strict-Transport-Security": [
      "max-age=15552000; includeSubDomains; preload"
    ],
    "Vary": [
      "X-HTTP-Method-Override"
    ],
    "X-Content-Type-Options": [
      "nosniff"
    ],
    "X-Powered-By": [
      "Sails <sailsjs.org>"
    ]
  }
}```