-
Notifications
You must be signed in to change notification settings - Fork 63
In-app payment methods #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Also added: functions to encode/decode Facebook's "signed requests". Refactored signature generation a little. |
lib/facebook.ex
Outdated
| * https://developers.facebook.com/docs/graph-api/reference/payment/dispute | ||
| """ | ||
| @spec dispute(object_id, access_token, dispute_reason) :: resp | ||
| def dispute(payment_id, access_token, reason) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer that having the name payment_dispute to make it clear when reading code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
lib/facebook.ex
Outdated
| * https://developers.facebook.com/docs/graph-api/reference/payment/refunds | ||
| """ | ||
| # credo:disable-for-lines:1 Credo.Check.Readability.MaxLineLength | ||
| @spec refunds(object_id, access_token, currency, amount, refunds_reason) :: resp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here, payment_refunds
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
lib/facebook.ex
Outdated
|
|
||
| @doc """ | ||
| Decodes a signed request from a client SDK (in-app payments), verifies the | ||
| signature and -if valid- returns its contents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why the dashes around if valid? IIRC dashes don't do any special kind of formatting, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should have been brackets, I changed the sentence a bit to make it more understandable.
| {:ok, signature} <- Base.url_decode64(signature_str), | ||
| _signature_verification = ^signature <- signature(payload_str), | ||
| {:ok, payload} <- Base.url_decode64(payload_str), | ||
| {:ok, payload} <- JSON.decode(payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this should be doable in a simpler way.
What's the purpose of the guard in the function? If signed_request is not a binary and you call that function then there won't be another function executed instead.
Also why the with with another guard (if you split a binary it should still be a binary)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm quite new to Elixir, maybe it really can be done better: I used the inner guards to ensure there won't be nil values. Which, you're right, is complete nonsense in the case of split() as it doesn't return nil values. I'll remove them.
However, guard'ing the function itself prevents it from being called with a wrong value and raise an exception instead of trying to call split() with a wrong argument. What do you think about that? How could I do it better?
mweibel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. In general these seem to be sensible additions and changes 👍
|
:/ didn't pay attention when squash merging those commits manually. They're in master now but without your author info. Sucks, sorry! |
|
Published version 0.18.0 with both of your changes. |
|
@mweibel no worries, I'm glad I can switch to the official version again :) I work with facebook.ex on a daily basis at the moment, so there may be more PRs. I hope you don't mind ;) |
Consists of two parts to support in-app payment calls:
appsecrettoapp_secretand addedapp_idconfig option to be able to supplyapp_access_token()method (with deprecation warnings)payment,disputeandrefundscalls