shaz3e/peach-payment

Peach payment hosted checkout

1.0.1 2023-11-27 15:34 UTC

This package is auto-updated.

Last update: 2024-10-10 15:23:05 UTC


README

Total Downloads Latest Stable Version License

Install Peach Payment in Laravel

composer require shaz3e/peach-payment

Add service provider

'providers' => [
    Shaz3e\PeachPayment\Providers\PeachPaymentServiceProvider::class,
]

Publish the config file

php artisan vendor:publish --tag=peach-payment-config

Update .env Data

php artisan update:peach-payment-config

How to Use

Watch YouTube Video Tutorials with details instructions and customization

YouTube Video

use Shaz3e\PeachPayment\Helpers\PeachPayment;

// Use the following code within your controller method
/**
 * Update in .env previously and get it from config
 */
$entityId = config('peach-payment.entity_id');
/**
 * Dynamic amount should be float
 * It can be passed via request
 */
$amount = (float) $request->amount;
/**
 * Return URL is optional
 * If you want user to redirect to another URL of your approved domain you can use the following
 * Do not use / at the beginnig of the $return_url as it will generate URL i.e. config('peach-payment.domain').'/'.$return_url.'/?PeachPaymentOrder='.$order_number
 */
$return_url = 'after-main-domain/route/sub-route/?PeachPaymentOrder=OID123456789'; // Optional

/**
 * Create new request for PeachPayment helper
 */
$peachPayment = new  PeachPayment();
/**
 * Generate token and initiate the request
 */
$checkoutData = $peachPayment->createCheckout($amount);
/**
 * Optional
 * Get Order Number if you want to update record in database
 * suggest me this is just for reconcile purpose
 * $checkoutData['order_number'] = OID.time()
 */
$order_number = $checkoutData['order_number'];
/**
 * CheckoutId is unique id generated by PeachPayment
 * This should be passed to render the form in blade template
 */
$checkoutId = $checkoutData['checkoutId'];
return  view('your.view', compact('entityId', 'checkoutId'));

In your.view use the following code.

<div id="payment-form"></div>
<script src="{{ config('peach-payment.' . config('peach-payment.environment') . '.embedded_checkout_url') }}"></script>
<script>
    const checkout = Checkout.initiate({
        key: "{{ $entityId }}",
        checkoutId: "{{ $checkoutId }}",
    });

    checkout.render("#payment-form");
</script>

When you run php artisan update:peach-payment-config it will ask you the following.

  1. What is your PEACHPAYMENT_ENVIRONMENT?
  2. What is your PEACHPAYMENT_ENTITY_ID?
  3. What is your PEACHPAYMENT_CLIENT_ID?
  4. What is your PEACHPAYMENT_CLIENT_SECRET?
  5. What is your PEACHPAYMENT_MERCHANT_ID?
  6. What is your PEACHPAYMENT_DOMAIN?
  7. What is your PEACHPAYMENT_CURRENCY?

After updating env data visit yourwebsite.com/peachpayment and it will fatch token and initiate the checkout at PeachPayment

Test Credit Cards https://developer.peachpayments.com/docs/reference-test-and-go-live

Contributing

License

Peach Payment Embed Checkout with Laravel is licensed under the MIT license. Enjoy!

Credit