/** * Update an webhook. * * @param array $params * * @return \Shoperti\PayMe\Contracts\ResponseInterface */ public function update($params = []) { $id = Arr::get($params, 'id', null); if (!$id) { throw new InvalidArgumentException('We need an id'); } return $this->gateway->commit('put', $this->gateway->buildUrlFromString('webhooks/stores/' . $id), $params); }
/** * Create a customer. * * @param string[] $attributes * * @return \Shoperti\PayMe\Contracts\ResponseInterface */ public function create($attributes = []) { $params['email'] = Arr::get($attributes, 'email'); $params['description'] = Arr::get($attributes, 'name'); if (isset($attributes['card'])) { $params['card'] = Arr::get($attributes, 'card', []); } return $this->gateway->commit('post', $this->gateway->buildUrlFromString('customers'), $params); }
/** * Find an event by its id. * * @param int|string $id * @param array $options * * @return \Shoperti\PayMe\Contracts\ResponseInterface */ public function find($id, array $options = []) { $event = Arr::get($options, 'event'); if (!$event) { throw new InvalidArgumentException("You must specify the 'event' key in the options array"); } $endpoint = null; switch ($event) { case 'charge.created': case 'charge.succeeded': case 'charge.refunded': case 'charge.cancelled': case 'charge.failed': case 'charge.rescored.to.decline': $endpoint = 'charges'; break; case 'chargeback.created': case 'chargeback.accepted': case 'chargeback.rejected': $endpoint = 'charges'; break; case 'fee.refund.succeeded': case 'fee.succeeded': $endpoint = 'charges'; break; case 'order.activated': case 'order.cancelled': case 'order.completed': case 'order.created': case 'order.expired': case 'order.payment.cancelled': case 'order.payment.received': $endpoint = 'charges'; break; case 'payout.created': case 'payout.failed': case 'payout.succeeded': $endpoint = 'charges'; break; case 'spei.received': $endpoint = 'charges'; break; case 'subscription.charge.failed': $endpoint = 'charges'; break; case 'transfer.succeeded': $endpoint = 'charges'; break; } if (!$endpoint) { throw new InvalidArgumentException(sprintf("The specified event '%s' is not valid", $event)); } /* @var \Shoperti\PayMe\Response $response */ $response = $this->gateway->commit('get', $this->gateway->buildUrlFromString("{$endpoint}/{$id}")); $response->type = $event; return $response; }
/** * Add order params to request. * * @param string[] $params * @param int $money * @param string[] $options * * @return array */ protected function addOrder(array $params, $money, array $options) { $params['description'] = Helper::ascii(Arr::get($options, 'description', 'PayMe Purchase')); $params['currency'] = Arr::get($options, 'currency', $this->gateway->getCurrency()); $params['amount'] = $this->gateway->amount($money); if (isset($options['reference'])) { $params['metadata']['reference'] = Arr::get($options, 'reference'); } return $params; }
/** * Store a credit card. * * @param string $creditcard * @param string[] $options * * @return \Shoperti\PayMe\Contracts\ResponseInterface */ public function create($creditcard, $options = []) { if (isset($options['customer'])) { $params['card'] = $creditcard; return $this->gateway->commit('post', $this->gateway->buildUrlFromString('customers/' . $options['customer'] . '/cards'), $params); } else { $params['email'] = Arr::get($options, 'email'); $params['description'] = Arr::get($options, 'name'); $params['card'] = $creditcard; return $this->gateway->commit('post', $this->gateway->buildUrlFromString('customers'), $params); } }
/** * Add customer to request. * * @param string[] $params * @param string[] $options * * @return array */ protected function addCustomer(array $params, array $options) { $address = Arr::get($options, 'shipping_address', []); $params['customer'] = ['name' => Arr::get($options, 'first_name', ''), 'last_name' => Arr::get($options, 'last_name', ''), 'phone_number' => Arr::get($options, 'phone', ''), 'email' => Arr::get($options, 'email', ''), 'requires_account' => false, 'address' => ['city' => Arr::get($address, 'city', ''), 'state' => Arr::get($address, 'state', ''), 'line1' => Arr::get($address, 'address1', ''), 'postal_code' => Arr::get($address, 'zip', ''), 'line2' => Arr::get($address, 'address2', ''), 'line3' => '', 'country_code' => Arr::get($address, 'country', '')]]; return $params; }
/** * Add Shipping address to request. * * @param string[] $params * @param string[] $options * * @return array */ protected function addShippingAddress(array $params, array $options) { if ($address = Arr::get($options, 'shipping_address')) { $params['details']['shipment'] = []; $params['details']['shipment']['carrier'] = Arr::get($address, 'carrier'); $params['details']['shipment']['service'] = Arr::get($address, 'service'); $params['details']['shipment']['price'] = Arr::get($address, 'price'); $params['details']['shipment']['address']['street1'] = Arr::get($address, 'address1'); $params['details']['shipment']['address']['street2'] = Arr::get($address, 'address2'); $params['details']['shipment']['address']['street3'] = Arr::get($address, 'address3'); $params['details']['shipment']['address']['city'] = Arr::get($address, 'city'); $params['details']['shipment']['address']['state'] = Arr::get($address, 'state'); $params['details']['shipment']['address']['zip'] = Arr::get($address, 'zip'); $params['details']['shipment']['address']['country'] = Arr::get($address, 'country'); } return $params; }
/** * Add order details params. * * @param string[] $params * @param string[] $options * * @return array */ protected function addCustomer(array $params, array $options) { $params['customer_name'] = Arr::get($options, 'name', ''); $params['customer_email'] = Arr::get($options, 'email', ''); return $params; }
/** * Add payout billing to request. * * @param string[] $params * @param string[] $options * * @return mixed */ protected function addPayoutBilling(array $params, array $options) { $params['billing_address'] = []; $params['billing_address']['tax_id'] = Arr::get($options, 'tax_id'); // RFC return $params; }
/** * Add Shipping address to request. * * @param string[] $params * @param string[] $options * * @return array */ protected function addShippingAddress(array $params, array $options) { if ($address = Arr::get($options, 'shipping_address')) { $params['ADDROVERRIDE'] = 1; $params['PAYMENTREQUEST_0_SHIPPINGAMT'] = $this->gateway->amount(Arr::get($address, 'price', 0)); $params['PAYMENTREQUEST_0_SHIPTOSTREET'] = Arr::get($address, 'address1'); $params['PAYMENTREQUEST_0_SHIPTOSTREET2'] = Arr::get($address, 'address2'); $params['PAYMENTREQUEST_0_SHIPTOCITY'] = Arr::get($address, 'city'); $params['PAYMENTREQUEST_0_SHIPTOSTATE'] = Arr::get($address, 'state'); $params['PAYMENTREQUEST_0_SHIPTOZIP'] = Arr::get($address, 'zip'); $params['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = Arr::get($address, 'country'); } return $params; }
/** * Map reference to response. * * @param array $response * * @return string|null */ protected function getAuthorization($response) { $object = Arr::get($response, 'object'); if ($object == 'customer') { return Arr::get($response, 'default_card_id'); } elseif ($object == 'card') { return Arr::get($response, 'customer_id'); } elseif ($object == 'payee') { return Arr::get($response, 'id'); } elseif ($object == 'transfer') { return Arr::get($response, 'id'); } elseif ($object == 'event') { return Arr::get($response, 'id'); } if (isset($response['payment_method']['auth_code'])) { return $response['payment_method']['auth_code']; } elseif (isset($response['payment_method']['barcode_url'])) { return $response['payment_method']['barcode_url']; } elseif (isset($response['payment_method']['clabe'])) { return $response['payment_method']['clabe']; } }
/** * Map PayPal response to reference. * * @param array $response * @param bool $isRedirect * * @return string */ public function getReference($response, $isRedirect) { if ($isRedirect) { return Arr::get($response, 'TOKEN', ''); } foreach (['REFUNDTRANSACTIONID', 'TRANSACTIONID', 'PAYMENTINFO_0_TRANSACTIONID', 'AUTHORIZATIONID'] as $key) { if (isset($response[$key])) { return $response[$key]; } } }
/** * Map HTTP response to transaction object. * * @param bool $success * @param array $response * * @return \Shoperti\PayMe\Contracts\ResponseInterface */ public function mapResponse($success, $response) { return (new Response())->setRaw($response)->map(['isRedirect' => false, 'success' => $success, 'reference' => $success ? $response['id'] : null, 'message' => $success ? 'Transaction approved' : Arr::get($response, 'message'), 'test' => $this->getTest($response), 'authorization' => $success ? $this->getAuthorization($response) : false, 'status' => $success ? $this->getStatus($response) : new Status('failed'), 'errorCode' => $success ? null : $this->getErrorCode(Arr::get($response, 'code')), 'type' => array_key_exists('type', $response) ? Arr::get($response, 'type') : Arr::get($response, 'object')]); }
/** * Map Stripe response to error code object. * * @param array $error * * @return \Shoperti\PayMe\ErrorCode */ protected function getErrorCode($error) { $code = Arr::get($error, 'code', $error['type']); switch ($code) { case 'invalid_expiry_month': case 'invalid_expiry_year': return new ErrorCode('invalid_expiry_date'); break; case 'invalid_number': case 'incorrect_number': case 'invalid_cvc': case 'incorrect_zip': case 'card_declined': case 'expired_card': case 'processing_error': return new ErrorCode($code); break; case 'missing': return new ErrorCode('config_error'); break; } }