{"id":209,"date":"2010-01-14T15:33:40","date_gmt":"2010-01-14T19:33:40","guid":{"rendered":"http:\/\/www.johnconde.net\/blog\/?p=209"},"modified":"2023-01-08T12:10:41","modified_gmt":"2023-01-08T16:10:41","slug":"handling-authorize-net-silent-post-with-php","status":"publish","type":"post","link":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/handling-authorize-net-silent-post-with-php\/","title":{"rendered":"Handling Authorize.Net Silent Post with PHP"},"content":{"rendered":"<p>Handling Authorize.Net Silent Post submissions with PHP, or any language for that matter, is easy. It&#8217;s really no different then receiving a form submission. You just need to know to expect. I took care of that in my <a href=\"\/blog\/all-about-authorize-nets-silent-post\/\">All About Authorize.Net&#8217;s Silent Post<\/a> article.<\/p>\n<p>But still, some people need it spelled out for them. But, in any case, this code snippet takes a response and determines the status of it (i.e. approved, declined, expired card, or error):<\/p>\n<pre lang=\"php\" line=\"1\">\r\n<?php \/\/ Get the subscription ID if it is available. \r\n\/\/ Otherwise $subscription_id will be set to zero. \r\n$subscription_id = (int) $_POST['x_subscription_id']; \r\n\/\/ Check to see if we got a valid subscription ID. \r\n\/\/ If so, do something with it. \r\nif ($subscription_id) { \r\n    \/\/ Get the response code. 1 is success, 2 is decline, 3 is error \r\n    $response_code = (int) $_POST['x_response_code']; \r\n    \/\/ Get the reason code. 8 is expired card. \r\n    $reason_code = (int) $_POST['x_response_reason_code']; \r\n    if ($response_code == 1) { \r\n        \/\/ Approved! \r\n        \/\/ Some useful fields might include: \r\n        \/\/ $authorization_code = $_POST['x_auth_code']; \r\n        \/\/ $avs_verify_result = $_POST['x_avs_code']; \r\n        \/\/ $transaction_id = $_POST['x_trans_id']; \r\n        \/\/ $customer_id = $_POST['x_cust_id']; \r\n    } \r\n    else if ($response_code == 2) { \r\n        \/\/ Declined \r\n    } \r\n    else if ($response_code == 3 &amp;&amp; $reason_code == 8) { \r\n        \/\/ An expired card \r\n    } \r\n    else { \r\n        \/\/ Other error \r\n    } \r\n} ?>\r\n<\/pre>\n<p>What you do once you determine the status of a POST response is up to you. Typically updating a database with the result of the transaction is done although the majority of the time this is only done with recurring subscription payments as immediate payments should be logged immediately as opposed to waiting for a Silent Post request.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Handling Authorize.Net Silent Post submissions with PHP, or any language for that matter, is easy. It&#8217;s really no different then receiving a form submission. You just need to know to expect. This code snippet takes a response and determines the status of it (i.e. approved, declined, expired card, or error). <a href=\"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/handling-authorize-net-silent-post-with-php\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[16],"tags":[60,50,84],"class_list":["post-209","post","type-post","status-publish","format-standard","hentry","category-programming","tag-authorizenet","tag-php","tag-silent-post"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pwpo4-3n","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/posts\/209","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/comments?post=209"}],"version-history":[{"count":9,"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/posts\/209\/revisions"}],"predecessor-version":[{"id":765,"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/posts\/209\/revisions\/765"}],"wp:attachment":[{"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/media?parent=209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/categories?post=209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/website-0f9bf4a4.hpx.ppi.temporary.site\/blog\/wp-json\/wp\/v2\/tags?post=209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}