Skip to content

Instantly share code, notes, and snippets.

@srinidhiprabandham
Last active January 11, 2018 11:57
Show Gist options
  • Save srinidhiprabandham/909ade04ae3215fc61037738a7c9414d to your computer and use it in GitHub Desktop.
Save srinidhiprabandham/909ade04ae3215fc61037738a7c9414d to your computer and use it in GitHub Desktop.
Target Partial payment understanding.

Problem :- Target has some instances where there are contracts that are not able to process the partial payments thus impacting Stats in Orsedd.

Steps that I took to see what was wrong :-

  1. Check if we are getting the "PaymentStatus" notification from target. [This is coming along from Target side].

  2. Checked the difference b/w several notifications that has successfull Payment and those that had failed.

    Taught that this was happening due to the fact that some of the failed payments did not have a call with status open But this was not so, as some examples that we checked indeed had status of "open" and status "ok" that was sent by Target.

  3. Followed up with Wes, and he suggested that we try writing an integration test for the same, which does the following :-

    Step 1: replicate current observed behaviour.

    Step 2: define new behavior, see specs fail

    Step 3: fix code so spec succeed

  4. Went through the code base to check the flow.

    First when a contract is created we make a call to the Target gateway with a "followup" method

    Orsedd::Http.post('https://www.targetpay.com/wap/followup.php5', post_options(), content_type: 'application/x-www-form-urlencoded', timeout: 60, retry: 0, log: true)
    

    Based on the success / failure status of the above response we will create a new "DirectBillingHistory" which looks at the config_profiles price_in_cents and sets that as the amount off the billing history.

    Then an Async callback comes from target to our server with the actual payment notification to the URL http://target.orsedd.com/target/direct_billing/payment_status This in-turn executes the worker Orsedd::Plugin::PaymentGateway::TargetDirectBilling::PaymentStatusMessageWorker

    Which first checks for a "exising payment" (That should have been created during the above follow up step) Then it checks for the status of the payment and updates the "Billing History"'s status.

(Did not see any place where the price_in_cents is updated in this file) [so not sure why the partial payments, considering the fact that price for the Billing History is already set in the last step]

So I changed the code to initialize the BilingHistory with a price_in_cents of 0.

And as we get the induvidual pieces of the billing nontification we process each one and update the billing history accordingly.

My Implementation is pushed to https://github.com/MobsterLimited/orsedd/tree/target-partial-payment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment