承接 albert-finaru/php-card-composer 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

albert-finaru/php-card-composer

Composer 安装命令:

composer require albert-finaru/php-card-composer

包简介

Set of library that give you the means to incorporate NETOPIA Payments functionality into your website applications and mobile apps.

README 文档

README

Parsedown

NETOPIA Payments

NETOPIA Payments Composer

Installation

Run the following command from root of your project

  • composer require netopia/payment

or

  • add the "netopia/payment" to your composer.json file like the following example

      "require": {
          ...
          "netopia/payment": "^1.0",
          ...
      }
    

    and then run the following command from your Terminal

    composer install

Example

An example of Payment Request in Laravel
...

use Netopia\Payment\Address;
use Netopia\Payment\Invoice;
use Netopia\Payment\Request\Card;

...

class ExampleController extends Controller
{
    /**
     * all payment requests will be sent to the NETOPIA Payments server
     * SANDBOX : http://sandboxsecure.mobilpay.ro
     * LIVE : https://secure.mobilpay.ro
     */
    public $paymentUrl;
    /**
     * NETOPIA Payments is working only with Certificate. Each NETOPIA partner (merchant) has a certificate.
     * From your Admin panel you can download the Certificate.
     * is located in Admin -> Conturi de comerciant -> Detalii -> Setari securitate
     * the var $x509FilePath is path of your certificate in your platform
     * i.e: /home/certificates/public.cer
     */
    public $x509FilePath;
    /**
     * Billing Address
     */
    public $billingAddress;
    /**
     * Shipping Address
     */
    public $shippingAddress;
    
    ...
    
    public function index()
    {
        $this->paymentUrl   = 'http://sandboxsecure.mobilpay.ro';
        $this->x509FilePath = '/home/certificates/sandbox.XXXX-XXXX-XXXX-XXXX-XXXX.public.cer';
        try {
            $paymentRequest = new Card();
            $paymentRequest->signature  = 'XXXX-XXXX-XXXX-XXXX-XXXX';//signature - generated by mobilpay.ro for every merchant account
            $paymentRequest->orderId    = md5(uniqid(rand())); // order_id should be unique for a merchant account
            $paymentRequest->confirmUrl = 'https://example.test/card/success'; // is where mobilPay redirects the client once the payment process is finished and is MANDATORY
            $paymentRequest->returnUrl  = 'https://example.test/ipn';// is where mobilPay will send the payment result and is MANDATORY

            /*
             * Invoices info
             */
            $paymentRequest->invoice = new Invoice();
            $paymentRequest->invoice->currency  = 'RON';
            $paymentRequest->invoice->amount    = '20.00';
            $paymentRequest->invoice->tokenId   = null;
            $paymentRequest->invoice->details   = "Payment Via Composer library";

            /*
             * Billing Info
             */
            $this->billingAddress = new Address();
            $this->billingAddress->type         = "person"; //should be "person" / "company"
            $this->billingAddress->firstName    = "Billing name";
            $this->billingAddress->lastName     = "Billing LastName";
            $this->billingAddress->address      = "Bulevardul Ion Creangă, Nr 00";
            $this->billingAddress->email        = "test@billing.com";
            $this->billingAddress->mobilePhone  = "0732123456";
            $paymentRequest->invoice->setBillingAddress($this->billingAddress);

            /*
             * Shipping
             */
            $this->shippingAddress = new Address();
            $this->shippingAddress->type        = "person"; //should be "person" / "company"
            $this->shippingAddress->firstName   = "Shipping Name";
            $this->shippingAddress->lastName    = "Shipping LastName";
            $this->shippingAddress->address     = "Bulevardul Mihai Eminescu, Nr 00";
            $this->shippingAddress->email       = "test@shipping.com";
            $this->shippingAddress->mobilePhone = "0721234567";
            $paymentRequest->invoice->setShippingAddress($this->shippingAddress);

            /*
             * encrypting
             */
            $paymentRequest->encrypt($this->x509FilePath);

            /**
             * send the following data to NETOPIA Payments server
             * Method : POST
             * URL : $paymentUrl
             */
            $EnvKey = $paymentRequest->getEnvKey();
            $data   = $paymentRequest->getEncData();
        }catch (\Exception $e)
        {
            return "Oops, There is a problem!";
        }
    }
    ...
}    

An example of IPN in Laravel

...

use Netopia\Payment\Address;
use Netopia\Payment\Invoice;
use Netopia\Payment\Request\Card;
use Netopia\Payment\Request\Notify;
use Netopia\Payment\Request\PaymentAbstract;

...

class IpnsController extends Controller 
{

    ...

    public $errorCode;
    public $errorType;
    public $errorMessage;
    public $paymentUrl;
    public $x509FilePath;

    ...
    
    public function index()
    {
    ...
    
        $this->errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_NONE;
        $this->errorCode = 0;
        $this->errorMessage = '';

        $this->paymentUrl = 'http://sandboxsecure.mobilpay.ro';
        $this->x509FilePath = '/home/certificates/sandbox.XXXX-XXXX-XXXX-XXXX-XXXXprivate.key';


        if (strcasecmp($_SERVER['REQUEST_METHOD'], 'post') == 0){
            if(isset($_POST['env_key']) && isset($_POST['data'])){
                try {
                    $paymentRequestIpn = PaymentAbstract::factoryFromEncrypted($_POST['env_key'],$_POST['data'],$this->x509FilePath);
                    $rrn = $paymentRequestIpn->objPmNotify->rrn;
                    if ($paymentRequestIpn->objPmNotify->errorCode == 0) {
                        switch($paymentRequestIpn->objPmNotify->action){
                            case 'confirmed':
                                //update DB, SET status = "confirmed/captured"
                                $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage;
                                break;
                            case 'confirmed_pending':
                                //update DB, SET status = "pending"
                                $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage;
                                break;
                            case 'paid_pending':
                                //update DB, SET status = "pending"
                                $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage;
                                break;
                            case 'paid':
                                //update DB, SET status = "open/preauthorized"
                                $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage;
                                break;
                            case 'canceled':
                                //update DB, SET status = "canceled"
                                $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage;
                                break;
                            case 'credit':
                                //update DB, SET status = "refunded"
                                $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage;
                                break;
                            default:
                                $errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_PERMANENT;
                                $this->errorCode = PaymentAbstract::ERROR_CONFIRM_INVALID_ACTION;
                                $this->errorMessage = 'mobilpay_refference_action paramaters is invalid';
                        }
                    }else{
                        //update DB, SET status = "rejected"
                        $this->errorMessage = $paymentRequestIpn->objPmNotify->errorMessage;
                    }
                }catch (\Exception $e) {
                    $this->errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_TEMPORARY;
                    $this->errorCode = $e->getCode();
                    $this->errorMessage = $e->getMessage();
                }

            }else{
                $this->errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_PERMANENT;
                $this->errorCode = PaymentAbstract::ERROR_CONFIRM_INVALID_POST_PARAMETERS;
                $this->errorMessag = 'mobilpay.ro posted invalid parameters';
            }

        } else {
            $this->errorType = PaymentAbstract::CONFIRM_ERROR_TYPE_PERMANENT;
            $this->errorCode = PaymentAbstract::ERROR_CONFIRM_INVALID_POST_METHOD;
            $this->errorMessage = 'invalid request metod for payment confirmation';
        }

        /**
         * Communicate with NETOPIA Payments server
         */

        header('Content-type: application/xml');
        echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
        if($this->errorCode == 0)
        {
            echo "<crc>{$this->errorMessage}</crc>";
        }
        else
        {
            echo "<crc error_type=\"{$this->errorType}\" error_code=\"{$this->errorCode}\">{$this->errorMessage}</crc>";
        }

    }
}
Note / Suggestions
  • if there is issue with namespace in your platform , you can solve it by getting help from Service Providers. for ex. in Laravel you can define a provider and put in your vendor and then set your namespace from the composer.json

  • if in any case the Country , City , Zip code , ... is separated from the Address in your application , please merge it with Address and create full address for Billing/Shipping address.

albert-finaru/php-card-composer 适用场景与选型建议

albert-finaru/php-card-composer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 09 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 albert-finaru/php-card-composer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 albert-finaru/php-card-composer 我们能提供哪些服务?
定制开发 / 二次开发

基于 albert-finaru/php-card-composer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 9
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: AGPL-3.0-or-later
  • 更新时间: 2023-09-01