How to integration amazon pay payment gateway in codeigniter 3 - deesoft service

How to integration amazon pay payment gateway in codeigniter 3

Deepak Tailor Image
Deepak Tailor - Feb 12 2023
How to integration amazon pay payment gateway in codeigniter  3

To integrate Amazon Pay payment gateway in CodeIgniter 3, you can follow these steps:

1. Sign up for Amazon Pay Developer Account

2. Get the necessary Amazon Pay API credentials (Seller ID, MWS Access Key ID, and Secret Key).

3. Install CodeIgniter 3 and setup your project.

4. Add the Amazon Pay SDK to your project. You can either download the SDK and add it to your project or use composer to install the SDK.

5. Write the CodeIgniter controller to handle the payment process:

o Load the Amazon Pay library in your controller.
o Initialize the Amazon Pay object with your API credentials.
o Create a payment authorization, capture the payment, and handle the response.

6. Write the CodeIgniter view to display the Amazon Pay button and show the payment status. Here is an example of the code you could use in your CodeIgniter controller:

class Payment extends CI_Controller
{
    public function index()
    {
        $this->load->library('amazon_pay');
        $amazon_pay = new Amazon_pay();

        $amazon_pay->set_access_key($this->config->item('access_key'));
        $amazon_pay->set_secret_key($this->config->item('secret_key'));
        $amazon_pay->set_seller_id($this->config->item('seller_id'));
        $amazon_pay->set_environment($this->config->item('environment'));

        $result = $amazon_pay->authorize_and_capture();

        if ($result === false) {
            $error = $amazon_pay->get_error();
        } else {
            $payment_status = $amazon_pay->get_payment_status();
        }

        $this->load->view('payment_view', array(
            'payment_status' => $payment_status,
            'error' => $error,
        ));
    }
}

Here is an example of the payment view file, payment_view.php:

<html>
<head>
    <script type="text/javascript" src="https://static-na.payments-amazon.com/OffAmazonPayments/us/js/Widgets.js"></script>
</head>
<body>
    <?php if (isset($payment_status) && $payment_status == 'Success'): ?>
        <h1>Payment Successful</h1>
    <?php elseif (isset($error)): ?>
        <h1>Payment Failed</h1>
        <p><?php echo $error; ?></p>
    <?php else: ?>
        <div id="AmazonPayButton"></div>
        <script type="text/javascript">
            OffAmazonPayments.Button("AmazonPayButton", "<?php echo $this->config->item('seller_id'); ?>", {
                type: "Paying",
                color: "Gold",
                size: "medium",
                authorization: function() {
                    loginOptions = {scope: "profile postal_code payments:widget payments:shipping_address", popup: true};
                    amazon.Login.authorize(loginOptions, "<?php echo site_url('payment'); ?>");
                },
                onError: function(error) {
                    // your error handling code
                }
            });
        </script>
    <?php endif; ?>
</body>
</html>

Additionally, you may also need to handle error cases, such as when the customer cancels the payment, when the payment fails, or when there is an error in the payment process. You can handle these cases by checking the response from Amazon Pay API and displaying appropriate messages or handling the errors accordingly.

Deepak Tailor Image
Deepak Tailor

My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
----
You can contact him at deepaktailor10@yahoo.in